How to cleanly import DWG w zero length lines
How to cleanly import DWG w zero length lines
I import manufacturer's DWG files, sometimes converted and scaled from PDF file, as source sketches in my interpretations of their parts when they do not have 3D models available. How dare they! I do not make the DWG that I am importing, and in my process I must cope with a wide variety of documentation errors by others.
Recently, I had one DWG import to 2d sketch which succeeded, but immediately had a yellow error icon once the sketch was closed. What's Wrong indicated that it contained a zero-length line, which would have been a tedious mystery to locate and remove. I probably could have proceeded with this as a minor error, but I am wary of small errors causing large issues when placed in a much larger context.
What I did to repair this was to select all entities in the sketch and make a block out of it. Apparently, blocks are allowed to have zero-length lines, but normal sketches are not. I fixed the block, closed the sketch, and there was no longer the yellow exclamation mark error on the sketch.
#whatswrong #zerolength #sketcherror #importdwg #makeblock
Recently, I had one DWG import to 2d sketch which succeeded, but immediately had a yellow error icon once the sketch was closed. What's Wrong indicated that it contained a zero-length line, which would have been a tedious mystery to locate and remove. I probably could have proceeded with this as a minor error, but I am wary of small errors causing large issues when placed in a much larger context.
What I did to repair this was to select all entities in the sketch and make a block out of it. Apparently, blocks are allowed to have zero-length lines, but normal sketches are not. I fixed the block, closed the sketch, and there was no longer the yellow exclamation mark error on the sketch.
#whatswrong #zerolength #sketcherror #importdwg #makeblock
- mattpeneguy
- Posts: 1386
- Joined: Tue Mar 09, 2021 11:14 am
- x 2489
- x 1899
Re: How to cleanly import DWG w zero length lines
I think I see the problem here...There's no such thing as a zero length line...They're called points...Jeez...
Re: How to cleanly import DWG w zero length lines
This feels dangerously close to zero thickness geometry.
- AlexLachance
- Posts: 2182
- Joined: Thu Mar 11, 2021 8:14 am
- Location: Quebec
- x 2363
- x 2013
Re: How to cleanly import DWG w zero length lines
I don't think you can remove these, unless a macro could locate "line" objects and then figure out which one are zero length and delete them.Tom G wrote: ↑Tue Apr 20, 2021 11:59 am I import manufacturer's DWG files, sometimes converted and scaled from PDF file, as source sketches in my interpretations of their parts when they do not have 3D models available. How dare they! I do not make the DWG that I am importing, and in my process I must cope with a wide variety of documentation errors by others.
Recently, I had one DWG import to 2d sketch which succeeded, but immediately had a yellow error icon once the sketch was closed. What's Wrong indicated that it contained a zero-length line, which would have been a tedious mystery to locate and remove. I probably could have proceeded with this as a minor error, but I am wary of small errors causing large issues when placed in a much larger context.
What I did to repair this was to select all entities in the sketch and make a block out of it. Apparently, blocks are allowed to have zero-length lines, but normal sketches are not. I fixed the block, closed the sketch, and there was no longer the yellow exclamation mark error on the sketch.
#whatswrong #zerolength #sketcherror #importdwg #makeblock
It's how the person drew the darn thing. Most likely there was a line segment that wasn't needed anymore and rather then delete it, he selected both lines and dragged one endpoint to the other. The line is still there, it's simply showing as if it were a "dot" now...
Whoever does that needs a course on how to draw
Re: How to cleanly import DWG w zero length lines
I wrote a macro that deletes small sketch entities, not used it for years but I remember it worked at the time.
Not sure what it will do to a zero length line, if it returns a zero length it should... but you can give it a try?
ps Nice find on the sketch block workaround
Not sure what it will do to a zero length line, if it returns a zero length it should... but you can give it a try?
ps Nice find on the sketch block workaround
- Attachments
-
- DeleteSketchEntitiesSmallerThan.swp
- (64 KiB) Downloaded 136 times
- Frederick_Law
- Posts: 1947
- Joined: Mon Mar 08, 2021 1:09 pm
- Location: Toronto
- x 1638
- x 1468
Re: How to cleanly import DWG w zero length lines
Drag a selection box at corners and delete. Repeat at all corners.
- elmarklammer
- Posts: 14
- Joined: Mon Apr 05, 2021 3:48 am
- x 1
- x 20
Re: How to cleanly import DWG w zero length lines
My tip would be to clean up the DWG before you import it. It pays of in the end. Especially on larger more detailed DWG.
I often need to bring in 3 Orthogonal views from old DWG 2D designs.
Draft sight and AutoCAD share the same commands. The most used tools are:
Remove uneeded objects:
- Selectmatching (sSelects drawing entities of the same type and with shared properties)
- IsolateEntities (Isolates specified entities by hiding all other entities)
- Unisolatentities (reverses Isolate function)
- Isolatelayer (isolates the Layers of selected entities)
- Selectionfilter (To create and apply selection filters)
Cleanup drawing
- Overkill (remove duplicate entities or overlapping segments of entities)
- DiscardDuplicates (same as above)
- Purge
- Clean (same as above)
Helpful commands
- lineweigth (Sets LineWeight options (dialog box variant))
- Linescale (Sets the global LineStyle scale factor)
- filedia (system variable controls whether you can see dialog boxes in CAD)
- check (very useful command to check errors in Drawing file and fix them Automatically)
Then import the DWG into part sketch. If you have many blocks in your dwg, explode them on import. This will speed the conversion process.
Select
- Use Repair sketch to remove small sketch entities and overlapping sketch lines and arcs.
Helper Tool:
A great tool if you have properly colored DWG
SolidWorks macro to organise segments from an imported dxf/dwg by color on layers
Imagine you get a large dxf or dwg which has been colorized by hand, without using layers. This macro will let you edit the drawing cleanly in SolidWorks, by placing all segments with the same color on specific layers.
'Layerize: SolidWorks macro to organise segments from an imported dxf/dwg by color on layers
'Author : Ph. Guglielmetti, (c) 2007, e-Systems Consulting Switzerland, all rights reserved
'Licence : you may use this macro for free, as long as this header is kept untouched.
'License : no support is provided, except for e-Systems customers
'Licence : it is forbidden to sell this code or publish it elsewhere without our permission
'Revision: 2007/01/30 PGu for AMBT
'Notes :
' 1) Don't forget to check "Microsoft Scripting Runtime" in References, needed for the Dictionary object
' 2) This macro is extremely slow if the drawing doc is visible. Minimize it when the macro runs to go faster
Sub main()
Dim swApp As SldWorks.SldWorks: Set swApp = Application.SldWorks
Dim doc As SldWorks.DrawingDoc: Set doc = swApp.ActiveDoc
Dim view As SldWorks.view: Set view = doc.GetFirstView
Dim sketch As SldWorks.sketch: Set sketch = view.GetSketch
Dim segs As Variant: segs = sketch.GetSketchSegments
Debug.Print UBound(segs)
Dim layermgr As SldWorks.layermgr: Set layermgr = doc.GetLayerManager
Dim layers As New dictionary
Dim s As Variant
For Each s In segs
Dim seg As SldWorks.SketchSegment: Set seg = s
Dim c As Long: c = seg.Color
If Not layers.Exists(c) Then ' create it
Dim name As String: name = "color " + Str(c)
Debug.Assert layermgr.AddLayer(name, "created by Layerize macro", seg.Color, seg.Style, seg.Width)
Call layers.Add(c, name)
Debug.Print "layer"; name; "created"
End If
seg.Layer = layers(c)
seg.LayerOverride = False
DoEvents
Next s
Debug.Print "finished"
End Sub
I often need to bring in 3 Orthogonal views from old DWG 2D designs.
Draft sight and AutoCAD share the same commands. The most used tools are:
Remove uneeded objects:
- Selectmatching (sSelects drawing entities of the same type and with shared properties)
- IsolateEntities (Isolates specified entities by hiding all other entities)
- Unisolatentities (reverses Isolate function)
- Isolatelayer (isolates the Layers of selected entities)
- Selectionfilter (To create and apply selection filters)
Cleanup drawing
- Overkill (remove duplicate entities or overlapping segments of entities)
- DiscardDuplicates (same as above)
- Purge
- Clean (same as above)
Helpful commands
- lineweigth (Sets LineWeight options (dialog box variant))
- Linescale (Sets the global LineStyle scale factor)
- filedia (system variable controls whether you can see dialog boxes in CAD)
- check (very useful command to check errors in Drawing file and fix them Automatically)
Then import the DWG into part sketch. If you have many blocks in your dwg, explode them on import. This will speed the conversion process.
Select
- Use Repair sketch to remove small sketch entities and overlapping sketch lines and arcs.
Helper Tool:
A great tool if you have properly colored DWG
SolidWorks macro to organise segments from an imported dxf/dwg by color on layers
Imagine you get a large dxf or dwg which has been colorized by hand, without using layers. This macro will let you edit the drawing cleanly in SolidWorks, by placing all segments with the same color on specific layers.
'Layerize: SolidWorks macro to organise segments from an imported dxf/dwg by color on layers
'Author : Ph. Guglielmetti, (c) 2007, e-Systems Consulting Switzerland, all rights reserved
'Licence : you may use this macro for free, as long as this header is kept untouched.
'License : no support is provided, except for e-Systems customers
'Licence : it is forbidden to sell this code or publish it elsewhere without our permission
'Revision: 2007/01/30 PGu for AMBT
'Notes :
' 1) Don't forget to check "Microsoft Scripting Runtime" in References, needed for the Dictionary object
' 2) This macro is extremely slow if the drawing doc is visible. Minimize it when the macro runs to go faster
Sub main()
Dim swApp As SldWorks.SldWorks: Set swApp = Application.SldWorks
Dim doc As SldWorks.DrawingDoc: Set doc = swApp.ActiveDoc
Dim view As SldWorks.view: Set view = doc.GetFirstView
Dim sketch As SldWorks.sketch: Set sketch = view.GetSketch
Dim segs As Variant: segs = sketch.GetSketchSegments
Debug.Print UBound(segs)
Dim layermgr As SldWorks.layermgr: Set layermgr = doc.GetLayerManager
Dim layers As New dictionary
Dim s As Variant
For Each s In segs
Dim seg As SldWorks.SketchSegment: Set seg = s
Dim c As Long: c = seg.Color
If Not layers.Exists(c) Then ' create it
Dim name As String: name = "color " + Str(c)
Debug.Assert layermgr.AddLayer(name, "created by Layerize macro", seg.Color, seg.Style, seg.Width)
Call layers.Add(c, name)
Debug.Print "layer"; name; "created"
End If
seg.Layer = layers(c)
seg.LayerOverride = False
DoEvents
Next s
Debug.Print "finished"
End Sub
- elmarklammer
- Posts: 14
- Joined: Mon Apr 05, 2021 3:48 am
- x 1
- x 20
Re: How to cleanly import DWG w zero length lines
Off Topic...Your avatar image makes me laugh...mattpeneguy wrote: ↑Tue Apr 20, 2021 12:07 pm I think I see the problem here...There's no such thing as a zero length line...They're called points...Jeez...
- mattpeneguy
- Posts: 1386
- Joined: Tue Mar 09, 2021 11:14 am
- x 2489
- x 1899
Re: How to cleanly import DWG w zero length lines
@elmarklammer,
I was trying to convey what I thought of the platform...Glad it brought you a laugh.
Feel free to use it...I'm contemplating using it over on the platform. Here's what I posted in the Banner thread: Here's a full resolution image, if you want to use it, here or wherever:
I was trying to convey what I thought of the platform...Glad it brought you a laugh.
Feel free to use it...I'm contemplating using it over on the platform. Here's what I posted in the Banner thread: Here's a full resolution image, if you want to use it, here or wherever:
- elmarklammer
- Posts: 14
- Joined: Mon Apr 05, 2021 3:48 am
- x 1
- x 20
Re: How to cleanly import DWG w zero length lines
clean...good humor...great stuff
- AlexLachance
- Posts: 2182
- Joined: Thu Mar 11, 2021 8:14 am
- Location: Quebec
- x 2363
- x 2013
Re: How to cleanly import DWG w zero length lines
The kind of sad part is it doesn't even need a hammer, it's already broken.mattpeneguy wrote: ↑Mon Apr 26, 2021 5:02 pm @elmarklammer,
I was trying to convey what I thought of the platform...Glad it brought you a laugh.
Feel free to use it...I'm contemplating using it over on the platform. Here's what I posted in the Banner thread:
3D Swym Hammer.png
Here's a full resolution image, if you want to use it, here or wherever:
shattered2.png
- mattpeneguy
- Posts: 1386
- Joined: Tue Mar 09, 2021 11:14 am
- x 2489
- x 1899
Re: How to cleanly import DWG w zero length lines
Fair enough.AlexLachance wrote: ↑Tue Apr 27, 2021 1:39 pm The kind of sad part is it doesn't even need a hammer, it's already broken.