Import dxf from illustrator with stroke color information

I have imported a dxf from illustrator that has stroke color information that I want to utilize to set line weight tags. When i select an edge I can see the color information in the entity info window but I’m struggle to find a way for Ruby to iterate through the model and select edges based on color and apply a line weight tag? Any insights greatly appreciated

Quick code snippet (does not really tested)

#define a hash with color rgba value 
# and Layer (Tag) name pairs
RGBA_TAGNAME ||= {
  [255, 0, 0, 255] => "light weight",
  [0, 255, 0, 255] => "heavy weight",
  [0, 0, 255, 255] => "butterfly weight"
}
model = Sketchup.active_model
entities = model.active_entities
layers = model.layers
entities.grep(Sketchup::Edge){|e|
  next unless e.material
  rgba = e.material.color.to_a
  next unless RGBA_TAGNAME.key?(rgba)
  layer = layers.add(RGBA_TAGNAME[rgba])
  e.layer = layers[layer.name]
  #optional:
  layer.color = rgba
}

This will only iterate for edges at the model root entities. (Anyway, assigning tag to edges or faces is not recommended workflow in Sketchup…)

Some references:
https://ruby-doc.org/core-2.7.2/Hash.html

https://ruby.sketchup.com/Sketchup/Drawingelement.html#layer-instance_method

https://ruby.sketchup.com/Sketchup/Layers.html#add-instance_method

https://ruby.sketchup.com/Sketchup/Drawingelement.html#material-instance_method

https://ruby.sketchup.com/Sketchup/Material.html#color-instance_method

https://ruby.sketchup.com/Sketchup/Color.html#to_a-instance_method

1 Like

Thanks for this I’ll give it a go. I guess I could select all edges with a certain color group then and tag the group?

I do not really understand what you mean. What you would like achieve? What is your goal at the end?
Share your Ruby code, your model, screenshot and explain it more clearly, please!

I’ve been working through this with Chat GPT. My goal is to import a DXF converted from a SVG in illustrator with stroke color infomation and use that to group and tag my line weights. Here’s the code to accomplish this which seems to work
batch import DXF02.rb (5.9 KB)
Combined_SVGs.dxf (146.8 KB)


Obviously This is just a simple example that will be replaced with Architectural drawings

ChatGpt is not magic… you should understand how to code with Ruby first

2 Likes

SketchUp does not have lines nor line weights. It is a 3D modeler that has edges (which are infinitely thin. Ie, edges have no actual thickness. They are a boundary between faces which connect vertices.)

LayOut, which is the paperspace companion to SketchUp, does have 2D lines and line thickness.

1 Like

Hi Dan, I use both on a regular basis and wanted to batch the tedious process of converting my 2D drawings derived from orthographic camera views in blender that clip my model to create sectional plans and elevations. I use grease pencil modifier to create the lines and export it as an svg with stroke colors with each camera view bound to a frame on my timeline. I import into illustrator where I batch arrange the frames/views in a tiled fashion and export as a dxf. Both of these processes are automated with a python script in blender and a Java script in illustrator. I then import the combined dxf into sketchup where I explode all components and group the views based on their frame tags. Then within each group I group again based on the edges material color and these groups I name and tag with my line weight tags.
The whole process seems absurd when I describe it here but working in 3D in blender to produce architectural designs and Archviz is really powerful and being able to then derive all my 2D drawings through the method outlined is fantastic, especially now that I’ve automated it. Layout’s dimensioning and annotation tools are really good although I’m now looking at how I can automate dimensioning for example a room’s interior wall and openings, cabinetry etc in geometry nodes in blender as it is still a time consuming process in Layout. I hope this explains my goal here.
Thanks
Ezra

If Blender is so good, why import into SketchUp?

And, doesn’t Blender have a SKP exporter?

Using the SketchUp APIs for SketchUp and LayOut, the creation of 2D views in a .layout document can be automated from a .skp 3D model file.

Why do so many people praise Blender so much but no one ever shows any concrete results from modelling and producing documentation from it?

3 Likes

ArchViz = / = ArchBuild