Jump to content
JimMac

2/3 working deviation lsp

Recommended Posts

JimMac

Hello all - I'm jim - New to forum, and auto cad.

 

Over the last few weeks ive been using this site and others to learn AutoCad. I have gleaned lots of useful information however i'm struggling with UCS rotations/ Drawing 3D in a lsp.

 

I'm half way through developing my first lsp that calculates the difference in X,Y,Y. It then draws lines showing deviation directions (for example deviation from design).

X and Y devition lines seem to be working ( not fully tested negative coordinates yet) but I cannot resolve the Z line. I have highlighted area that is causing problems. and have attached a screen dump of current results.

 

I know it is probably somthing simple I am missing, but I think i have been looking at the problem t0o long, with too much autocad inexperience :)

 

If anyone has any ideas or pointers please let me know.

 

Regards

JM

 

 

 


;Written by JM 2019
;STILL UNDER CONSTRUCTION
									

(defun rtd (r) (/ (* r 180.0) pi))     ;Angle conversions
(defun dtr (d) (/ (* d pi) 180.0))     ;Angle conversions
				

(defun c:delta
	       (/ p1 p2	x1 x2 y1 y2 z1 z2 xp yp	zp dx dy dz coorddiff
		Tolerence)

  (command "_UCS" "World")		;Ensure WCS is current


  (setq	osm	  (getvar "osmode")
	ocmd	  (getvar "cmdecho")
	textStyle (getvar "textstyle")
  )

					;(setq Tolerence (getdist "\nTolorence in mm : "))

  (while
    (setq p1 (getpoint "\nPick Design Position: "))
     (setq x1 (car p1))
     (setq y1 (cadr p1))
     (setq z1 (caddr p1))
     (setq p2 (getpoint "\nPick Asbuilt Position: "))
     (setq x2 (car p2))
     (setq y2 (cadr p2))
     (setq z2 (caddr p2))

     (cond ((<= x1 x2)
	    (setq dx (rtos (- x2 x1)))
	    (setq xp (polar p2 (dtr 0) 50))
	    (command "line" p2 xp "")
	   ) ;_ end of the first condition x
	   ((> x1 x2)
	    (setq dx (rtos (- x1 x2)))
	    (setq xp (polar p2 (dtr 0) -50))
	    (command "line" p2 xp "")
	   ) ;_ end of the first condition x
     ) ;_ end of cond statement for X

     (cond ((<= y1 y2)
	    (setq dy (rtos (- y2 y1)))
	    (setq yp (polar p2 (dtr 90) 50))
	    (command "line" p2 yp "")
	   ) ;_ end of the first condition y
	   ((>= y1 y2)
	    (setq dx (rtos (- y1 y2)))
	    (setq yp (polar p2 (dtr 90) -50))
	    (command "line" p2 yp "")
	   ) ;_ end of the second condition y
     ) ;_ end of cond statement for y

    
;**********************************************************Rotation Causing 3D Line issue?
     (cond ((<= z1 z2)                            
	    (setq dz (rtos (- z2 z1)))
	    (command "_UCS" "y" -90)
	    (setq zp (polar p2 (dtr 180) -50))
	    (command "line" p2 zp "")
	   ) ;_ end of the first condition z
	   ((> z1 z2)
	    (setq dz (rtos (- z1 z2)))
	    (command "_UCS" "y" -90)
	    (setq zp (polar p2 (dtr 180) 50))
	    (command "line" p2 zp "")
	   ) ;_ end of the second condition z
     ) ;_ end of cond statement for z
;**********************************************************Rotation Causing 3D Line issue?

    
     ;;Displayes co-ordinates
     (command "_UCS" "World")
     (setq coorddiff (strcat dx "," dy "," dz))
     (command "text" "j" "c" p2 25 -45 coorddiff)
  )
)

 

Z line in wrong position.PNG

Share this post


Link to post
Share on other sites
Roy_043

There are two main issues with your code:

 

1.

You are using command calls to create new entities. This means that the OSMODE setting will have an impact on the behavior of your program. You are already storing the OSMODE setting, but you should set it to 0 prior to creating the line and text entities.

 

2.

When you change the UCS in the part of the code that deals with the delta Z, you have to consider that p2 is expressed in the WCS. To use p2 in the new UCS you have to translate it:

(trans p2 0 1) ; Translate p2 from the WCS to the current UCS.

 

There are more efficient ways to write the program, but if you address these two issues your code should work.

 

Edited by Roy_043

Share this post


Link to post
Share on other sites
JimMac
4 hours ago, Roy_043 said:

(trans p2 0 1) ; Translate p2 from the WCS to the current UCS

 Hi Roy, Thanks for the pointers.

 

After translating p2 should its values change? as when i "watch window" p2 the values don't change. although they clearly must to be drawing the line in a new position.

I think i will need to read up about them now, as I can't be using it correctly. Anyway thanks again.

Cheers JM

 

Share this post


Link to post
Share on other sites
Lee Mac
19 minutes ago, JimMac said:

After translating p2 should its values change? as when i "watch window" p2 the values don't change.

 

The coordinate values will only change in the Watch Window if you redefine the variable p2 with the result of the trans expression, e.g.:

(setq p2 (trans p2 0 1))

 

Share this post


Link to post
Share on other sites
JimMac

Ahh, thanks. Lee & Roy

 

I've a working prototype now that I can build on, Its not pretty, loads of room for improvemnet.

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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