atom feed2 messages in com.googlegroups.sketchup3dSlightly modified "PipeAlongPath.rb" ...
FromSent OnAttachments
JG BersonJul 4, 2009 12:35 pm 
jgbJul 4, 2009 2:09 pm 
Subject:Slightly modified "PipeAlongPath.rb" Defaults to INCH rather than Metric.
From:JG Berson (jgbe@rogers.com)
Date:Jul 4, 2009 12:35:42 pm
List:com.googlegroups.sketchup3d

Pipe Along Path is one of my mainstay plugins. However it default opens to metric, 110mm outer diameter, 100mm inner diameter and 24 sides. I work in inches. Doing so since I was a kid, ain't gonna change now. Canada is now a quasi metric country anyway. However, truth be told, I am somewhat metric/FPS bilingual.

PAP always bugged me by being metric default, but at least it had the manners to stay the way you set it for the session.

Anyway, I decided to look into its script to see if I could make it default startup in inches. Was easy. This is a very well written and internally documented script. The writer had nicely put the default startup parameters in 1 statement, and I only had to change those, and a very few error checks back to default. I was going to rename it PipeAlongPath-in.rb but there is some filename check at the end of script, and I did not want (nor have the time) to monkey with it.

So the attached version (noted in its version notes) now defaults to "Inch, 1 inch outside, 0 inches inside and 8 sides".

Now if only PAP would clean up after itself to optionally delete guides...... I wouldn't delete the original path, in the very common case of needing to undo and redo the PAP slightly different.

jgb

--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "SketchUp General" group. To post to this group, send email to Sket@googlegroups.com To unsubscribe from this group, send email to SketchUp3d+unsu@googlegroups.com For more options, visit this group at http://groups.google.com/group/SketchUp3d?hl=en -~----------~----~----~----~------~----~------~--~---

###--------------------------------------------------------------------- # Name : PipeAlongPath # # Description : Creates circular faced 'followme' pipe extrusions along # a path - # Use it to make pipes, ducts etc, starting from a selection of # joined edges # # Author : TIG (c) 9/2005 # based on TubeAlongPath.rb which itself was from an original # wall making idea by Didier Bur and using some vertex array # ideas from Rick Wilson # # Usage : # Select joined lines, arcs, circles, curves, etc. # Select "Pipe Along Path" from the Plugins menu. # In the dialog choose units (mm/inch), enter outside and inside # diameters, number of segements and then OK. Setting are # remembered during a session. # # The extrusion is made*. # *The extrusion is grouped so it does not interact with adjacent # surfaces - afterwards just explode it if appropriate. Edit it # to intesect with model and tidy up to make Tees etc... # # The pipe also has construction points added at each vertex. # These can be used for snapping, if not wanted 'erase # construction geometry' will remove them globally or just within # a group that you are editing. # # One Undo will remove the construction points, another the Pipe. # # The default for extrusion face segments is 24, the minimum is 3. # # The alignment is 'Centroid' - along pipe's centre line. # # The diameter is always measured square to the vector of the # first path's line. A diameter that is less than the length of # pieces of path edge might give correct but unexpected # extrusions, which might need manually tidying... # Closed loop paths are fully extruded. # Multiple arcs and other complex 3D paths might give unexpected # results. Note that SketchUp can't handle very small faces in # its FollowMe mode - so any Arc bends of 8" radius or less that # have the same radius for the pipe (o/d) applied will cause a # crash and "bug splat" and are trapped out BUT note that similar # radii in 'welded' Curves are NOT easily trappable and so they # will always cause a crash with a "bug-splat", so avoid using # these type of path with small radii bends/pipes - or you can # keep it but use 'scale' as explained below... # IF you must have this matching small diameter pipe and arc or # welded elbow bends then to get it to work make the path a # group, scale it by a factor so it's larger (say x10), then # edit it and use this tool within it applying the diameter x10, # after it's all made scale the group back down by x0.1 and # explode it and it'll all be OK. # # Both diameters cannot be zero and will return an error. # If one of the diamaters is zero then you get a 'tube' rather # than a pipe. # If the diamaters entered are equal the inside one is taken as # zero and you will then get a 'tube' rather than a pipe. # If the inside's diameter is greater than the outside's then # they are swapped. # A branching path returns an error as 'FollowMe' can't decide # which path to take. # Selected edges that are not joined (i.e. they don't all have # common ends-starts) will not be extruded - only the first edge # or joined group of edges will extrude. # # Type : Tool # # Version : # 1.0 18/9/5 first release. # 1.1 18/9/5 visual segmenting of arced sections etc addressed. # 1.2 9/2/6 centrepoints added at vertices of non-looped paths, # occasional reversed faces on single 'up' line fixed. # 1.3 16/2/6 undo of cpoints fixed, diam <8" with matching arc # elbow bend radius bug splat trapped (but not curves). # 1.4 2/5/6 group name -> OD=xx ID=nn with " or mm as units. # 1.5 3/5/6 Transposed I/O fixed (sorry!). # 1.6 4Jul09 Edited default startup to
"inch, 1, 0 and 8 sides" : JG Berson # 1.6 12/5/7 @error=0 ### fix # ###--------------------------------------------------------------------- require 'sketchup.rb' ### def pipe_along_path model = Sketchup.active_model entities = model.active_entities ss = model.selection ### show VCB and status info Sketchup::set_status_text("Pipe Along Path... PARAMETERS...", SB_PROMPT) Sketchup::set_status_text(" ", SB_VCB_LABEL) Sketchup::set_status_text(" ", SB_VCB_VALUE) ### if ss.empty? Sketchup::set_status_text("Pipe Along Path... NO SELECTION ! ", SB_PROMPT) UI.messagebox("No Selection to Extrude Pipe.") return nil end ### trap for small radius arcs aflag=false arads=[] for s in ss if s.typename=="Edge" if s.curve if s.curve.typename=="ArcCurve" if s.curve.radius < 200.mm aflag=true arads=arads.push(s.curve.radius) end else for e in s.curve.edges if e.curve.typename=="ArcCurve" if e.curve.radius < 200.mm aflag=true arads=arads.push(e.curve.radius) end end end#for end end end end#for ### #################################################################### def get_vertices ### this next bit is mainly thanks to Rick Wilson's weld.rb ### @error=0 ### 20070512 model=Sketchup.active_model ents=model.active_entities @sel=model.selection sl=@sel.length verts=[] edges=[] @newVerts=[] startEdge=startVert=nil #DELETE NON-EDGES, GET THE VERTICES @sel.each {|item| edges.push(item) if item.typename=="Edge"} edges.each {|edge| verts.push(edge.vertices)} verts.flatten! #FIND AN END VERTEX vertsShort=[] vertsLong=[] vertsEnds=[] ### to ensure array is only ends ### verts.each do |v| if vertsLong.include?(v) vertsShort.push(v) else vertsLong.push(v) end end vertsLong.each do |v| ### to ensure array is only ends ### if not vertsShort.include?(v) vertsEnds.push(v) end end ### 17/8/5 ### to ensure array is only ends ### if vertsEnds.length==0 ### i.e. it's looped ### ### path start or end ? if @theEnd==0 startVert=vertsLong.first @startVert=$endVert=nil ###1.2 startEdge=startVert.edges.first else startVert=vertsLong.last @startVert=$endVert=nil ###1.2 startEdge=startVert.edges.first end ### closed=true else if vertsEnds.length != 2 Sketchup::set_status_text("Pipe Along Path... PATH ERROR ! ", SB_PROMPT) UI.messagebox("The selected Path either branches or is not continuous !
\nCannot make a Pipe Extrusion ! \nRe-select a single continuous path... ") @error=1 return nil else ### path start or end ? if @theEnd==0 startVert=vertsEnds.first @startVert=startVert ###1.2 @endVert=vertsLong.last ###1.2 else startVert=vertsEnds.last @startVert=startVert ###1.2 @endVert=vertsLong.first ###1.2 end ### closed=false startEdge=startVert.edges.first end end @sel.clear #SORT VERTICES, LIMITING TO THOSE IN THE SELECTION SET if startVert==startEdge.start @newVerts=[startVert] counter=0 while @newVerts.length < verts.length edges.each do |edge| if edge.end==@newVerts.last @newVerts.push(edge.start) elsif edge.start==@newVerts.last @newVerts.push(edge.end) end end counter+=1 if counter > verts.length Sketchup::set_status_text("Pipe Along Path... ERROR ! ", SB_PROMPT) return nil if UI.messagebox("There seems to be a problem. Try again?",
MB_YESNO)!=6 @newVerts.reverse! reversed=true end end else @newVerts=[startVert] counter=0 while @newVerts.length < verts.length edges.each do |edge| if edge.end==@newVerts.last @newVerts.push(edge.start) elsif edge.start==@newVerts.last @newVerts.push(edge.end) end end counter+=1 if counter > verts.length Sketchup::set_status_text("Pipe Along Path... ERROR ! ", SB_PROMPT) return nil if UI.messagebox("There seems to be a problem. Try again?",
MB_YESNO)!=6 @newVerts.reverse! reversed=true end end end @newVerts.reverse! if reversed #CONVERT VERTICES TO POINT3Ds @newVerts.collect!{|x| x.position} ### now have an array of vertices in order with NO forced closed loop ... end ### get_vertices ### @theEnd=0 get_vertices if @error==1 return nil end ### dialog ############################################################# units = ["mm","inch"] enums = [units.join("|")] if not $diamOutIn values = ["inch", 1.0, 0.0, 8] else values = [$unitsIn, $diamOutIn, $diamInIn, $psegmentsIn] end prompts = ["Units (mm / inch) : ", "Outside Diameter: ", "Inside Diameter: ",
"Number of Circle Segments: "] results = inputbox prompts, values, enums, "Pipe Parameters" return nil if not results ### i.e. the user cancelled the operation $unitsIn = results[0] $diamOutIn = results[1] $diamInIn = results[2] $psegmentsIn = results[3] if $diamOutIn == 0 and $diamInIn == 0 ### can't BOTH be 0 ### $diamOutIn = 1..0 UI.messagebox("Two Zero Diameters NOT allowed ! ") return nil end if $diamOutIn == $diamInIn ### can't be same so Inner=0 ### $diamInIn = 0 UI.messagebox("Equal Diameters NOT allowed !\nInner Diameter is reset to
Zero. ") end if $diamInIn > $diamOutIn ### Inner can't be bigger ### diamInIntemp = $diamInIn $diamInIn = $diamOutIn $diamOutIn = diamInIntemp UI.messagebox("Inner Diameter NOT allowed to be bigger than Outer!\nInner is
reset to be the smaller value. ") end if $psegmentsIn < 3 $psegmentsIn = 8 UI.messagebox("Fewer than 3 Faces are NOT allowed !\nDefaulting to 8. ") end segs = $psegmentsIn radiusO = $diamOutIn / 2 radiusI = $diamInIn / 2 ### - do units stuff - ### if $unitsIn == "mm" radiusI = radiusI.mm radiusO = radiusO.mm txtO=$diamOutIn.to_s+"mm" txtI=$diamInIn.to_s+"mm" else radiusI = radiusI.inch radiusO = radiusO.inch txtO=$diamOutIn.to_s+"\"" txtI=$diamInIn.to_s+"\"" end ### check for small arcs and == diameter bug-splatters 1.3 dflag=false for r in arads dflag=true if r.inch == radiusO end if aflag and dflag ###1.3 Sketchup::set_status_text("Pipe Along Path... RADIUS ? ! ", SB_PROMPT) UI.messagebox("The Radius of at least one Arc in the Path is < 200mm(~8\")
\nand it also matches the Pipe's Outer Radius (#{radiusO}) ! \nThis will cause
SketchUp to Bug-Splat and Crash !! \nHowever it CAN be done this way - \nScale
up the Path and Diameters by x10, \nuse this Tool and then Scale down the Path
and Pipe by x0.1...\n\nExiting...") return nil end ### NOW - do main stuff - ### Sketchup::set_status_text("Pipe Along Path... MAKING PIPE...", SB_PROMPT) model.start_operation "Pipe Along Path" ###1.3 pt1 = @newVerts[0] pt2 = @newVerts[1] vec = pt1.vector_to pt2 group=entities.add_group entities=group.entities if not radiusI == 0.0 ###1.1 circleI = entities.add_circle pt1, vec, radiusI, segs baseI = entities.add_face circleI end circleO = entities.add_circle pt1, vec, radiusO, segs baseO = entities.add_face circleO if not radiusI == 0.0 ###1.1 baseI.erase! end theFace = baseO if pt1.x == pt2.x and pt1.y == pt2.y and pt1.z < pt2.z ### flip so not inside
out ! ### theFace.reverse! end entits = model.active_entities ###1.1 @@theEdges= [] 0.upto(@newVerts.length-2) do |i| if @startVert ###1.2 theFace.reverse! if @newVerts.length < 3 and theFace.normal == [0,0,-1] and
@startVert.position.z < @endVert.position.z end ###1.2 @@theEdges[i] = entits.add_line(@newVerts[i],@newVerts[i+1]) ### make
vertices into edges ###1.1 end ### follow me along selected edges theExtrusion=theFace.reverse!.followme @@theEdges ### ### add name group.name="OD="+txtO+" ID="+txtI ### model.commit_operation ### restore selection set of edges and display them model.start_operation "Pipe's Cpoints" ###1.3 theEdgeX = [] 0.upto(@newVerts.length-2) do |i| theEdgeX[i] = entits.add_line(@newVerts[i],@newVerts[i+1]) ### make vertices
into edges ###1.1 entities.add_cpoint @newVerts[i] ###if @startVert ###1.2 entities.add_cpoint @newVerts[i+1] ###if @startVert ###1.2 entities.add_cpoint [0,0,0.1.mm] if @newVerts[i]==[0,0,0] or
@newVerts[i+1]==[0,0,0] ###if @startVert ###1.2 end model.commit_operation ###1.3 model.selection.clear model.selection.add theEdgeX end ### end def ### ### menu bits ### if( not file_loaded?("PipeAlongPath.rb") )### ###if( not file_loaded?("28-PipeAlongPath.rb") )### UI.menu("Plugins").add_separator### UI.menu("Plugins").add_item("Pipe Along Path") { pipe_along_path }### ###$submenu2.add_item("Pipe Along Path") { pipe_along_path }### end ###file_loaded("28-PipeAlongPath.rb")### file_loaded("PipeAlongPath.rb")### ###---------------------------------------------------------------------