Jump to content

Recommended Posts

Posted

Morning everyone,

Hopefully someone can help me out here.

 

I am trying to write a bit of code that draws a LWpolyline using entmake.

So far I have that part working great. This basically just draws a LWPOLYLINE from pt1 with a 5m radius arc to pt3 then a straight line to pt4 then another arc from pt4 to pt2 and ends there. pt1 and pt2 are user selected points using Getpoint OR ENTGET, depending on the object type that is at pt1 or pt2.

The intent of this section of the lisp is to draw this polyline in the same direction the user is viewing it no matter which way the UCS is.

Using this section of the code, it works perfectly fine for most scenarios. Once I rotate the UCS 180 degrees, it starts drawing the lwpolyline up side down. Can anyone help me out with this?

(setq pt1 (trans pt1 1 0)
	 pt2 (trans pt2 1 0)
	 )
(if (< (car pt1)(car pt2)) ;If you select the HP first then the LP, this area gets skipped
	(setq ang (angle pt1 pt2)
	      pt3 (polar pt1 (+ ang (DtR 45)) 7.0711)
	      pt4 (polar pt2 (+ ang (DtR 135)) 7.0711)
	      pt-lst (list pt1 pt3 pt4 pt2)
	      bulge-list '(-0.414214 0.0 -0.414214 0.0)
	      )
   	(setq ang (angle pt2 pt1)
	      pt3 (polar pt2 (+ ang (DtR 45)) 7.0711)
	      pt4 (polar pt1 (+ ang (DtR 135)) 7.0711)
	      pt-lst (list pt1 pt4 pt3 pt2)
	      bulge-list '(-0.414214 0.0 -0.414214 0.0)
	      )

   )
(setq apron (entmake
	       (apply
		  (FUNCTION APPEND)
		  (cons (list '(0 . "LWPOLYLINE")
			      '(100 . "AcDbEntity")
			      '(67 . 0)
			      '(410 . "Model")
			      (cons 8 lay3)
			      '(100 . "AcDbPolyline")
			      (CONS 90 (LENGTH pt-lst))   ; Vertices
			      '(70 . 0)
			      )
			(MAPCAR (FUNCTION LIST)
				(MAPCAR (FUNCTION (LAMBDA (a) (CONS 10 a))) pt-lst)
				(MAPCAR (FUNCTION (LAMBDA (b) (CONS 42 b))) bulge-list)
				)
			)
		  )
	       );_ entmake
      );_ setq

image.png.53612c1fca436254648bead9670a1e6b.png

 

The image above is how I want the user to see the lwpolyline no matter what the ucs is, including no matter how its rotated.

Thanks.

Posted

Hi,

What if you just changed

(setq pt1 (trans pt1 1 0)
	 pt2 (trans pt2 1 0)
	 )

in

(setq pt1 (trans pt1 1 0)
	 pt2 (trans pt2 1 0)
	 pt2 (list (+ (car pt1) (distance pt1 pt2)) (cadr pt1))
	 )

 

Posted
1 hour ago, Tsuky said:

Hi,

What if you just changed

(setq pt1 (trans pt1 1 0)
	 pt2 (trans pt2 1 0)
	 )

in

(setq pt1 (trans pt1 1 0)
	 pt2 (trans pt2 1 0)
	 pt2 (list (+ (car pt1) (distance pt1 pt2)) (cadr pt1))
	 )

 

Hi Tsuky,

 

This basically just made the lwpolyline draw according to the WCS, not the UCS that I need it too.

We typically switch UCS relative to the world when doing a specific type of work, this also includes the UCS being rotated various degrees relative to the WCS.

I am trying to figure out how TRANS actually works.

I thought that if you used TRANS on a point lets say, that you could use essentially set the value of that point to be the trans of the current UCS. That doesnt seem to be the case.

Meaning (setq pt1 (3.0 5.0 0.0)) is my WCS point.

But if I am a rotated UCS I could add (setq pt1 (trans pt1 1 0)) and it would translate to that UCS point to for every occurrence of pt1. That doesnt seem to be the case.

I often use Line in my CAD drawing to find out where my points are landing as a way to test things.

So when I draw a line I type !pt1 to get the first point of the line and when I am in a rotated UCS that first point isnt where I expect it to land. Which is confusing to me.

Posted

You can create polyline in WCS, then change to UCS, create UCS matrix and finally transform object from WCS to UCS... The key is matrix (you have to build it manually) and (transformby) method...

Posted
26 minutes ago, marko_ribar said:

You can create polyline in WCS, then change to UCS, create UCS matrix and finally transform object from WCS to UCS... The key is matrix (you have to build it manually) and (transformby) method...

lol if I understood how to do any of that, I would try just that!

Posted

Is this what you want?

((lambda ( / )
(setq pt1 (getpoint "\nFirst point:"))
(setq pt2 (getpoint pt1 "\nEnd point:"))
(setq pt1 (trans pt1 1 0)
	 pt2 (trans pt2 1 0)
	 )
(if (< (car pt1)(car pt2)) ;If you select the HP first then the LP, this area gets skipped
	(setq ang (angle pt1 pt2)
	      pt3 (polar pt1 (+ ang (* pi 0.25)) 7.0711)
	      pt4 (polar pt2 (+ ang (* pi 0.75)) 7.0711)
	      pt-lst (list pt1 pt3 pt4 pt2)
	      bulge-list '(-0.414214 0.0 -0.414214 0.0)
	      )
   	(setq ang (angle pt2 pt1)
	      pt3 (polar pt2 (+ ang (* pi 0.25)) 7.0711)
	      pt4 (polar pt1 (+ ang (* pi 0.75)) 7.0711)
	      pt-lst (list pt1 pt4 pt3 pt2)
	      bulge-list '(-0.414214 0.0 -0.414214 0.0)
	      )

   )
(setq apron (entmake
	       (apply
		  (FUNCTION APPEND)
		  (cons (list '(0 . "LWPOLYLINE")
			      '(100 . "AcDbEntity")
			      '(67 . 0)
			      '(410 . "Model")
			      (cons 8 (getvar "CLAYER"))
			      '(100 . "AcDbPolyline")
			      (CONS 90 (LENGTH pt-lst))   ; Vertices
			      '(70 . 0)
			      )
			(MAPCAR (FUNCTION LIST)
				(MAPCAR (FUNCTION (LAMBDA (a) (CONS 10 a))) pt-lst)
				(MAPCAR (FUNCTION (LAMBDA (b) (CONS 42 b))) bulge-list)
				)
			)
		  )
	       );_ entmake
      )
))

 

Posted (edited)

Because of problems with the entmake and using trans have you thought about just go back to Command Pline. It works in current UCS. A couple of examples of insulation drawn in a UCS matching white line. 

image.png.d5a74acdb725614a3c0dd565e6171bec.png

 

A arc is supported in a pline sequence. Part of insul code.

; now put pts 3,4,5,6
		(command "arc" "ce" p3 "arc" "-180" "l" p5 "arc" "ce" p6 p7 "l" p8)

 

Edited by BIGAL
  • Like 1
Posted
37 minutes ago, Tsuky said:

Is this what you want?

((lambda ( / )
(setq pt1 (getpoint "\nFirst point:"))
(setq pt2 (getpoint pt1 "\nEnd point:"))
(setq pt1 (trans pt1 1 0)
	 pt2 (trans pt2 1 0)
	 )
(if (< (car pt1)(car pt2)) ;If you select the HP first then the LP, this area gets skipped
	(setq ang (angle pt1 pt2)
	      pt3 (polar pt1 (+ ang (* pi 0.25)) 7.0711)
	      pt4 (polar pt2 (+ ang (* pi 0.75)) 7.0711)
	      pt-lst (list pt1 pt3 pt4 pt2)
	      bulge-list '(-0.414214 0.0 -0.414214 0.0)
	      )
   	(setq ang (angle pt2 pt1)
	      pt3 (polar pt2 (+ ang (* pi 0.25)) 7.0711)
	      pt4 (polar pt1 (+ ang (* pi 0.75)) 7.0711)
	      pt-lst (list pt1 pt4 pt3 pt2)
	      bulge-list '(-0.414214 0.0 -0.414214 0.0)
	      )

   )
(setq apron (entmake
	       (apply
		  (FUNCTION APPEND)
		  (cons (list '(0 . "LWPOLYLINE")
			      '(100 . "AcDbEntity")
			      '(67 . 0)
			      '(410 . "Model")
			      (cons 8 (getvar "CLAYER"))
			      '(100 . "AcDbPolyline")
			      (CONS 90 (LENGTH pt-lst))   ; Vertices
			      '(70 . 0)
			      )
			(MAPCAR (FUNCTION LIST)
				(MAPCAR (FUNCTION (LAMBDA (a) (CONS 10 a))) pt-lst)
				(MAPCAR (FUNCTION (LAMBDA (b) (CONS 42 b))) bulge-list)
				)
			)
		  )
	       );_ entmake
      )
))

 

Thanks Tsuky.

I think I just figured it out. 

I was on The Swamp forums and found something that I was able to adapt to my code and it seems to be working.

There is a post on there from a user named Gile https://www.theswamp.org/index.php?topic=13526.0 that explains and demonstrates how to use Trans for polylines.

What he posted fit perfectly with what I was trying to accomplish. I added it to my code and everything seems to be working correctly now.

Only thing I need to do now is figure out how to get my angles now at this rotated UCS and I am good to go.

Updated code is below if someone needs it.

;; --------------------------- DRAW THE REAR APRON --------------------------- ;;
   
    (if (< (car pt1)(car pt2)) ;If you select the HP first then the LP, this area gets skipped
	(setq ang (angle pt1 pt2)
	      pt3 (polar pt1 (+ ang (DtR 45)) 7.0711)
	      pt4 (polar pt2 (+ ang (DtR 135)) 7.0711)
	      pt-lst (list pt1 pt3 pt4 pt2)
	      bulge-list '(-0.414214 0.0 -0.414214 0.0)
	      )
   	(setq ang (angle pt2 pt1)
	      pt3 (polar pt2 (+ ang (DtR 45)) 7.0711)
	      pt4 (polar pt1 (+ ang (DtR 135)) 7.0711)
	      pt-lst (list pt1 pt4 pt3 pt2)
	      bulge-list '(0.414214 0.0 0.414214 0.0)
	      )

   ); 
(setq zdir (trans '(0 0 1) 1 0 T)
      elv  (caddr (trans (car pt-lst) 1 zdir))
)
   (setq apron (entmake
	       (apply
		  (function append)
		  (cons (list '(0 . "LWPOLYLINE")
			      '(100 . "AcDbEntity")
			      '(100 . "AcDbPolyline")
			      '(67 . 0)
			      '(410 . "Model")
			      (cons 8 lay3)
			      (cons 90 (length pt-lst))
			      '(70 . 0); 1 for closed 0 overwise
			      (cons 38 elv)
			      (cons 210 zdir)
			      );_ end list
			(mapcar (function list)
				(mapcar '(lambda (pt) (cons 10 (trans pt 1 zdir))) pt-lst)
				(mapcar '(lambda (bpt) (cons 42 bpt)) bulge-list)
				);_ mapcar
			);_ cons
		  );_ apply
	       );_ entmake
      );_  setq

 

Posted

@BIGAL

 

Hi Bigal, much appreciate you reply as always.

I was thinking about use the command Pline route, but I came across a forum post on The Swamp that helped solve the issue.

The entmake is making the polyline correctly now, no matter what UCS I am in.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...