Please forgive me in advance if I’m wrong somewhere in definitions or other things. I’m just learning).
With the help of ChatGPT) and the sample codes you all wrote (thanks), I’m trying to write my code. But faced the problem of welding lines into one polyline. ChatGPT gave me a couple dozen answers, but none of them work well for me. So I want to ask you to help me.
About your code. For example, I draw a rectangle with standard Sketchup tools and create a group from it (although it can also be a rhombus or a groove with two arcs, but these are always simple 2D elements). Then I run my code and add certain attributes, tags to the group, change it depending on the options selected and entered in the dialog box. The 2 options from the list that I can select involve some modification of the entities in the group. I need to weld all the edges around the perimeter (they should form a closed contour) and remove the face. And I have a problem with this).
Here is my code. Please help me to finish it.
model = Sketchup.active_model
selection = model.selection
if selection.length == 1 && selection[0].is_a?(Sketchup::Group)
if selection[0].entities.grep(Sketchup::Group).any?
UI.messagebox("ПОМИЛКА!!! Ви обрали декілька груп або компонент, або групу, яка містить у собі вкладені групи чи компоненти. Відредагуйте цю або створіть іншу групу")
return
end
prompts = ["Створити", "Назва", "Глибина", "Артикул"]
defaults = ["Паз", "", "", ""]
list = ["Паз|Паз в торець|Отвiр|Отвiр в торець|Завіса", "", "", ""]
input = UI.inputbox(prompts, defaults, list, "Введiть параметри")
return unless input
create, name, depth, article = input
dict_name = "ABF"
dict = selection[0].attribute_dictionary(dict_name,true)
if create == "Паз"
dict["intersect-group-b-id"] = 11111
dict["intersect-offset"] = 0.0
dict["is-intersect"] = true
dict["setting-name"] = name
layer_name = article.empty? ? "ABF_Groove_DEPTH#{depth}" : "ABF_Groove_DEPTH#{depth}-$#{article}"
group_name = "ABF_Intersect"
elsif create == "Паз в торець"
dict["intersect-group-b-id"] = 22222
dict["intersect-offset"] = 0.0
dict["is-intersect"] = true
dict["setting-name"] = name
layer_name = article.empty? ? "ABF_Groove_DEPTH#{depth}" : "ABF_Groove_DEPTH#{depth}-$#{article}"
group_name = "ABF_Intersect"
#Weld edges and erase faces
entities = selection[0]&.entities
if entities
faces = entities.select { |e| e.is_a?(Sketchup::Face) }
rectangle_face = faces.find { |f| f.vertices.length == 4 }
rectangle_face&.erase!
edges = entities.select { |e| e.is_a?(Sketchup::Edge) }
points = edges.map { |e| e.start.position } << edges.last.end.position
if points[0].x > points[1].x
points.reverse!
end
curve = entities.add_curve(points)
end
elsif create == "Отвiр"
dict["is-minifix-part-a"] = true
dict["minifix-group-b-id"] = 33333
dict["setting-name"] = name
layer_name= article.empty? ? "ABF_Hole_DEPTH#{depth}" : "ABF_Hole_DEPTH#{depth}-$#{article}"
group_name= "ABF_Hole"
selection[0].entities.each do |entity|
if entity.is_a?(Sketchup::Edge) && entity.curve && entity.curve.is_a?(Sketchup::ArcCurve)
entity.faces.each(&:erase!)
center_point = entity.curve.center
selection[0].entities.add_cpoint(center_point)
end
end
elsif create == "Отвiр в торець"
dict["minifix-group-a-id"] = 44444
dict["is-side-drill-depth"] = true
dict["is-minifix-part-b"] = true
dict["setting-name"] = name
layer_name = article.empty? ? "ABF-DSIDE-#{depth}" : "ABF-DSIDE-#{depth}-$#{article}"
group_name = "ABF_sideDrill"
#Weld edges and erase faces
entities = selection[0]&.entities
if entities
faces = entities.select { |e| e.is_a?(Sketchup::Face) }
rectangle_face = faces.find { |f| f.vertices.length == 4 }
rectangle_face&.erase!
edges = entities.select { |e| e.is_a?(Sketchup::Edge) }
points = edges.map { |e| e.start.position } << edges.last.end.position
if points[0].x > points[1].x
points.reverse!
end
curve = entities.add_curve(points)
end
elsif create == "Завіса"
dict["is-hinge-part-b"] = true
dict["hinge-group-a-id"] = 55555
dict["setting-name"] = name
layer_name= article.empty? ? "ABF_Hing_DEPTH#{depth}" : "ABF_Hing_DEPTH#{depth}-$#{article}"
group_name= "ABF_Hing"
selection[0].entities.each do |entity|
if entity.is_a?(Sketchup::Edge) && entity.curve && entity.curve.is_a?(Sketchup::ArcCurve)
entity.faces.each(&:erase!)
center_point = entity.curve.center
selection[0].entities.add_cpoint(center_point)
end
end
else
UI.messagebox("Невiрний параметр \"Створити\"")
return
end
layers= model.layers
layer= layers[layer_name]
unless layer
layer= layers.add(layer_name)
end
# Move all entities inside the selected group to the created layer
selection[0].entities.each { |entity| entity.layer=layer }
selection[0].name= group_name
end
model.active_view.invalidate
This is one more example of the fact that large language AI does not understand anything, it just assembles text based on examples and statistics in the data it was trained on. Even if the training data contained some examples of SketchUp Ruby API code found on the web, it seems likely it would have seen a lot more with no relevance to SketchUp and would therefore happily generate rubbish.
Two problems with the above comment and Ruby statement:
(1) SketchUp layers are not geometric containers. They do not “hold” entities and so entities cannot be “on” a layer (tag.) The layerproperty of an entity points at a shared layer object that the graphics engine uses to control display of the model.
(2) 98% of the time, ALL primitive geometric entities should use Layer0 (ie, display name "Untagged".)
Only complex objects (dimensions, callouts, section planes, etc.), guides, groups and component instances should be assigned to use other layers (tags.)
I know about it. But it’s a plugin for a plugin). If successful, this is required for further conversion to a dxf file. So we will get ready lines in layers.
.
In the current context I totally agree…the curve is the right term here.
So I mention it just for the sake of interest:
.
SketchUp does have (had) polylines...(click to expand)
SketchUp does have (had) polylines… at least literal.
Up to SU version 2021 (if I remember right) you can create such a 3d Polyline by using Freehand Tool when holding Shift key. For compatibility reason these are still there if you open older file in newer version of SU… but there is no method - as I know - to create these anymore.
I’m not sure if these are so called “geometric” entities, but sure these are Drawingelemnts, in the model can be displayed, moved, rotated, copied and scaled. You can assign a Tag and hide, however can not be “recognized” by the SketchUp inference engine, does not “interacting” with other Drawingelements and can not be further manipulated, converted, exploded…and so on… Selecting it only possible with “click and drag to the left” method.
#typename method retrieves the “Polyline3d” string and in Entity Info (or in Model Info & Component Statistics) they calling these as “3d Polylines”.
True. The FreeHand + feature came with the 2022.0 release. It appears that since then the SHIFT polyline draw mode was removed. See this topic (which I never noticed until now):
The object drawn with the Freehand tool’s base mode is a curve made up with connected edge objects. The curve is singly selectable with the Select tool.
What we can say is that the Freehand tool has been simplified to remove the polyline SHIFT feature since v2022.0.
The existence of Polyline3d objects was a well kept “secret” as the tool’s SHIFT polyline mode was not explained on the status bar with other modifiers.
The true Polyline3d objects always have been exposed to the C API. But never to the Ruby API.
Others and I have asked for a dedicated Polyline tool to create non-geometric 3D pathways that do not effect edges or faces. The SketchUp team’s responses have been mixed, some saying that true polylines will make a comeback, others saying polylines are goners.
The Markup tool in the iPad version can create watermarks on faces that does the same (eg. create non-inferencable elements) but they are pixelated (since they are textures)
It would have been nice to have the shift-freehand 3D polygone back on that version, because you have more control with a pencil than with a mouse.
(That was always my main obstruction towards the fenomenon)
@Wo3Dan ’s request back than was about finding a way to get rid of inferencing on objects’ geometry that doesn’t make sense to inference on at all in a way.
You don’t have to inference on hundreds of leaves of a plant or grass, for instance, the kind of stuf that makes a model crawl.
With CAD, you have an option to toggle on or of, but not on specific objects (me thinks) so it would make it more ‘SketchUppy’, I guess.
The annotation extension (and all others) cannot be used on the iPad version, which was why I would have liked it on that version.
Well, we are getting off topic a bit here. But nevertheless, I am always all for more user control of features that are important to a user’s workflow. The user is always going to know best how they need to use their software.
I very much like the idea of inferencing suppression for either entity-level, container level (group or instance) or layer/tag level. The latter might seem out of place as inferencing is to entity characteristics (upon, end vertices, midpoints, etc.,) but there will likely be users who “collect” and “treat” like objects using layer/tags. (So I include it in the list.)
This extension uses Overlays to merely display lines. These are not really an object in the model geometry database. They are really just descriptive data in an attribute dictionary and when displayed can be interacted with by the user.
So, again I ask interested persons who could benefit from a true native “PolyPath” tool to weigh in on the open feature request:
depends the context, I am a newbe to sketchup, and I was able to learn 95% of what I needed to know by using Chat GPT 4. It doesn’t always get it the first time, but generally with one or to very short refinement questions I can get good answers most of the time.