Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ideas on how to efficiently trace imported geometry?

14 REPLIES 14
Reply
Message 1 of 15
tpottebaum
324 Views, 14 Replies

Ideas on how to efficiently trace imported geometry?

Hello,

 

Been experimenting with AutoLISP to try and improve the process of tracing imported geometry using AutoCAD LT. For context, we manufacture precast wall panels that typically have 4" sheets of foam insulation in them. We lay these 4' x 8' sheets into the footprint of the panel, but they have a lot of cutouts due to embedded plates that are placed inside them. So, we run each of these sheets through a cnc machine to cut out what we need. Below is what I normally import into AutoCAD. 

 

tpottebaum_0-1735591954323.png

 

The following snip below would be the final product after I manually trace each cutout (in green). The blue rectangles are there for reference to show how each 4'x8' sheet would get laid out in this scenario.

 

tpottebaum_1-1735592303757.png

 

Does anyone have ideas on how I could improve this process? I've been tying to think of an AutoLISP code, but not sure how I could create anything that would be faster than simply tracing. Given it is an imported PDF, I imagine there isn't much to do here... but I thought I'd ask to see if anyone has any creative ideas :beaming_face_with_smiling_eyes:.  Thanks!

 

14 REPLIES 14
Message 2 of 15
Kent1Cooper
in reply to: tpottebaum

The blue could be done easily enough with a User Hatch pattern, with its origin set at the left end, assuming the overall isn't more than 8' high [or maybe even if it is].  Is the outer perimeter a single object like a closed Polyline?

 

On the green parts, is there anything in the way they import that can distinguish them from other objects of the same type in the drawing?  And what are they -- Polylines, or made up of individual Lines, or...?  If they're Polylines, and [for example] are the only closed Polylines, or the only ones of more than a certain area, or if there are widths involved that are unique to the different kinds of things, then AutoLisp can find them easily.

 

But if it can, do you then want to convert them to what you show as green, or draw over them as apparently do you manually with the originals remaining, or...?

 

A sample drawing....

Kent Cooper, AIA
Message 3 of 15
ec-cad
in reply to: tpottebaum

Any chance you could get the (original) file that the supplier uses for outputting the .pdf ?

Could they supply say a .dxf instead ?

Is scaling an issue ?

 

ECCAD

Message 4 of 15
tpottebaum
in reply to: Kent1Cooper

I only need a better way to do the green as of now. They do come in as polylines but the entire geometry comes in on the same layer. I can't find anything different about those lines in particular. The lines I need come in as open polylines as well.

 

Looks like I can just select each polyline and change it to a new layer and that would work fine. I can't think of any way for Autolisp to identify the lines I need. 

Message 5 of 15
tpottebaum
in reply to: ec-cad

We do get .dxf sometimes, but not all suppliers give us those and it typically takes them longer to send them, so I usually start the process using the pdf version.

 

Scaling isn't an issue here. When they do send the .dxf files we can simply turn off the layers we don't need and it leaves us with the cutouts. 

Message 6 of 15
ec-cad
in reply to: tpottebaum

Ok, I get it.

Can you upload a small sample .dwg with the .dxf image included ?

Maybe a Lisp with PEDIT or such will allow you to pick a few lines, and make a Polyline

and put it on a given layer ..

 

ECCAD

Message 7 of 15
tpottebaum
in reply to: ec-cad

Here is a .dwg with the imported and scaled pdf. 

Message 8 of 15
ec-cad
in reply to: tpottebaum

Thanks for the drawing.

I see there might be a chance of grabbing those polylines, by their 'Lineweight', and isolating them.

Some have 0.09mm, and others have 0.20mm and another 0.30mm.

If that is an indication of 'what' they are, maybe grab all, make (3) layers with different colors,

and put a copy of the different Lineweights on those layers ?

Shall I try that ?

ECCAD

Message 9 of 15
tpottebaum
in reply to: ec-cad

It looks like there are some other lines with that same lineweight. So, while it would quickly narrow down what I need, I think I would still have to do some work to clean it all up. 

 

I think I may be grasping at straws with this one... 

Message 10 of 15
ВeekeeCZ
in reply to: tpottebaum

I would focus on area. See what I get if I qselect all plines with area 250+ 

That could be done by simple routine... much faster than qs.

 

eekeeCZ_1-1735846779992.png

 

 

 

Message 11 of 15
ec-cad
in reply to: tpottebaum

Initial version. Drag/Drop into your drawing.

Let's go from there.

 

ECCAD

Message 12 of 15
Kent1Cooper
in reply to: tpottebaum

I was hoping the things you want green would be closed shapes, but they're [mostly] not.  Even the biggest outer-bounds Polyline, though it wraps around to where it starts, is not actually closed in AutoCAD's meaning.  In addition, there are complications like this:

Kent1Cooper_0-1735846489155.png

The upper red outline [as far as it goes] is a single Polyline, but the corresponding lower one is in two pieces, yellow and green.  So looking for certain characteristics might find some things you want and miss others.

 

And yes, I find that the stirrups [if that's the right word] are of the same lineweight as the things you want green, so lineweight is not going to be the distinguishing characteristic.

 

The non-Solid Hatching is done in independent single-segment Polylines -- another good reason to get it in DXF or better yet DWG format if available.  There would presumably be Layer distinctions, which should help.  What is the type of document from which they are generating the PDF's you get?

 

One thing that might be achievable, if it would help, would be to isolate at least all Polylines that contain only orthogonal segments.  That would at least bypass the stirrups and some of the associated parts, and the "stars" [whatever they are], and the screw- or bolt-heads, and hatching pieces.  But it would still catch some things you don't want.  Would such Polylines, but only those with segments no shorter than a certain length, be a reliable distinction?

Kent Cooper, AIA
Message 13 of 15
tpottebaum
in reply to: Kent1Cooper

Some suppliers provide DWGs. These have the cutouts in their own layer, so that makes it pretty easy for me. I'm just trying to find a better way of handling this when I don't have the DWGs.

 

The length of segments could help out... Possibly pairing this with the .lsp from @ec-cad could get very close to only having the desired lines left.

 

Was also curious if the number of segments in the polyline could help distinguish as well. A maximum number of segments may not be necessary as that might only be applicable to the stirrups and similar geometries, which would be eliminated by the orthogonal segment criteria. But, the cutouts I need should almost always be at least 3 segments. There are cases when there could be 2, but that's pretty rare, so I feel comfortable taking care of that situation manually if it arises. 

 

 

Message 14 of 15
Kent1Cooper
in reply to: tpottebaum


@tpottebaum wrote:

.... Was also curious if the number of segments in the polyline could help distinguish as well. .... 


Yes, (ssget) can filter for the number of vertices in a LWPolyline [the DXF 90 entry], even both ways  -- you could have it "see" only those with both more than [let's say] two and fewer than [let's say] 20 vertices.  Look into >relational tests< and >logical groupings<.

Kent Cooper, AIA
Message 15 of 15
ronjonp
in reply to: tpottebaum

@tpottebaum Give this a try. The preset values work with your sample drawing

 

(defun c:foo (/ ar b j ll m mn mx pts r s ur )
  ;; RJP » 2025-01-02
  (if (and (or (setq ar (getreal "\nEnter minimum area for cutout:<75>")) (setq ar 75))
	   (or (setq mn (getreal "\nEnter minimum bounding box side length:<1>")) (setq mn 1))
	   (or (setq mx (getreal "\nEnter maximum bounding box side length:<60>")) (setq mx 60))
	   (setq s (ssget '((0 . "LWPOLYLINE"))))
      )
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (cond ((and (> (vlax-curve-getarea e) ar)
		  (setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget e))))
		  (> (length pts) 3)
		  (setq a (mapcar '(lambda (r j) (rem (angle r j) pi)) pts (cdr pts)))
		  (vl-every '(lambda (x) (or (equal x 0 1E-2) (equal x (/ pi 2) 1E-2))) a)
	     )
	     (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
	     (setq b (mapcar 'abs (mapcar '- (vlax-safearray->list ll) (vlax-safearray->list ur))))
	     ;; Remove walls ( a side less than 1 unit )
	     ;; and remove boundaries ( a side greater than 60 units )
	     (if (and (> (car b) mn) (> (cadr b) mn) (< (car b) mx) (< (cadr b) mx))
	       (entmod (append (entget e) '((8 . "CUTOUT") (62 . 1))))
	     )
	    )
      )
    )
  )
  (princ)
)

 

 

2025-01-02_15-14-18.gif

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report