Jump to content

changing coordinates by 1


Mocaffiene

Recommended Posts

I've got a code that can draw a line offset from where a user clicks two locations and i can only get it to offset by 2 or more. for some reason anytime i try to offset by 1 is draws the line directly on top of old line

 

 

 

   (setq pt1 (getpoint "\nSelect Start Point: "))        ;GETS LOCATION OF FIRST MOUSE CLICK

   (setq pt2 (getpoint "\nSelect End Point: "))        ;GETS LOCATION OF SECOND MOUSE CLICK

 

    (setq ptx1 (car pt1))                    ;ptx1 is x-coor of pt1
    (setq pty1 (cadr pt1))                    ;pty1 is y-coor of pt1
    (setq ptx2 (car pt2))                    ;ptx2 is x-coor of pt2
    (setq pty2 (cadr pt2))                    ;pty2 is y-coor of pt2


          (setq ptx4 (+ ptx2 1))            
          (setq pty4 (+ pty2 1))
          (setq ptx5 (- ptx1 1))
          (setq pty5 (+ pty1 1))
          (setq pt4 (list ptx4 pty4 0))
          (setq pt5 (list ptx5 pty5 0))
          (command "LINE" pt4 pt5 "")

Link to comment
Share on other sites

As you've discovered, point input supplied to AutoLISP command calls will be impacted by any Object Snap modes active at the time that the command is invoked. However, rather than disabling Object Snap or modifying the OSMODE system variable (which in turn would requre the use of a local error handler to ensure that the original environment is restored), you can override all active snap modes by preceding the point input with the "_non" or "_none" modifier, e.g.:

(command "_.LINE" "_non" pt4 "_non" pt5 "") 

I describe this technique in my detail in my post here.

Link to comment
Share on other sites

To offer some food for thought, it is also worth noting that your code could be equivalently written in the following way:

(if (and (setq p (getpoint "\nSpecify start point: "))
         (setq q (getpoint p "\nSpecify end point: "))
    )
    (command "_.line" "_non" (mapcar '+ q '(1 1)) "_non" (mapcar '+ p '(-1 1)) "")
)

 

  • Like 1
Link to comment
Share on other sites

16 minutes ago, rkmcswain said:

@Lee Mac - am I remembering right..... if you use (entmake) - running object snaps are ignored?

 

Your memory serves you correctly @rkmcswain - though if using entmake, the defining coordinates must also be translated from UCS to WCS, and so this may be intimidating for a novice.

Link to comment
Share on other sites

Something like this note side is based on p1 p2 direction.

 

(defun c:test ( / ang off p1 p2 p3 p4)
(if (and (setq p1 (getpoint "\nSpecify start point: "))
         (setq p2 (getpoint p1 "\nSpecify end point: "))
    )
	(progn
	(setq ang (angle p1 p2))
	(setq off (getreal "\nEnter offset value "))
	(setq p3 (polar p1 (+ ang (/ pi 2.0)) off))
	(setq p4 (polar p2 (+ ang (/ pi 2.0)) off))
	(command "_.LINE" "_non" p3 "_non" p4 "")
	)
)
(princ)
)

 

Link to comment
Share on other sites

4 hours ago, Lee Mac said:

 

the defining coordinates must also be translated from UCS to WCS, and so this may be intimidating for a novice.

 

No worries @Lee Mac, novices are restricted to only working in WCS. 😉 

  • Funny 1
Link to comment
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
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...