How to cleanly import DWG w zero length lines

Use this space to ask how to do whatever you're trying to use SolidWorks to do.
User avatar
Tom G
Posts: 355
Joined: Tue Mar 09, 2021 9:26 am
Answers: 0
Location: Philadelphia, PA area
x 989
x 466

How to cleanly import DWG w zero length lines

Unread post by Tom G »

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
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: How to cleanly import DWG w zero length lines

Unread post by mattpeneguy »

I think I see the problem here...There's no such thing as a zero length line...They're called points...Jeez...
User avatar
bnemec
Posts: 1944
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2546
x 1400

Re: How to cleanly import DWG w zero length lines

Unread post by bnemec »

This feels dangerously close to zero thickness geometry.
User avatar
AlexLachance
Posts: 2184
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2364
x 2013

Re: How to cleanly import DWG w zero length lines

Unread post by AlexLachance »

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
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.


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
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 208
Contact:

Re: How to cleanly import DWG w zero length lines

Unread post by Rob »

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
Attachments
DeleteSketchEntitiesSmallerThan.swp
(64 KiB) Downloaded 143 times
User avatar
Frederick_Law
Posts: 1947
Joined: Mon Mar 08, 2021 1:09 pm
Answers: 8
Location: Toronto
x 1638
x 1470

Re: How to cleanly import DWG w zero length lines

Unread post by Frederick_Law »

Drag a selection box at corners and delete. Repeat at all corners.
User avatar
elmarklammer
Posts: 14
Joined: Mon Apr 05, 2021 3:48 am
Answers: 0
x 1
x 20

Re: How to cleanly import DWG w zero length lines

Unread post by elmarklammer »

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
User avatar
elmarklammer
Posts: 14
Joined: Mon Apr 05, 2021 3:48 am
Answers: 0
x 1
x 20

Re: How to cleanly import DWG w zero length lines

Unread post by elmarklammer »

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...
Off Topic...Your avatar image makes me laugh...
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: How to cleanly import DWG w zero length lines

Unread post by mattpeneguy »

@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
User avatar
elmarklammer
Posts: 14
Joined: Mon Apr 05, 2021 3:48 am
Answers: 0
x 1
x 20

Re: How to cleanly import DWG w zero length lines

Unread post by elmarklammer »

clean...good humor...great stuff
User avatar
AlexLachance
Posts: 2184
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2364
x 2013

Re: How to cleanly import DWG w zero length lines

Unread post by AlexLachance »

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
The kind of sad part is it doesn't even need a hammer, it's already broken.
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: How to cleanly import DWG w zero length lines

Unread post by mattpeneguy »

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.
Fair enough.
Post Reply