Jump to content

Autolisp function yields different results when ran on-screen vs. off-screen.


SebastianTheCrab

Recommended Posts

The source of the problem is a helper function drawportsegment:

(defun drawportsegment (loc portspacing / portw porth test)
(setq
	portw 2.0
	porth 1.0)

(command "rectangle"
	(list (- (car loc) (/ portw 2.0)) (cadr loc) 0.0)
	(list (+ (car loc) (/ portw 2.0)) (- (cadr loc) porth) 0.0))
(command "line"
	(list (car loc) (- (cadr loc) porth) 0.0)
	(list (car loc) (- (cadr loc) portspacing) 0.0)
	"")
)

As it is relevant information, the test function I wrote to interface with drawportsegment is testdps:

(defun c:testdps (/ loc portspacing)
(setq 
	loc (getpoint "\nwhere?")
	portspacing 2.0)

(drawportsegment loc portspacing))

Here is a direct comparison of this function running on-screen vs. off-screen:

 

aJ2cq2v.png

 

I do not understand why figure A is generated, as I would think from looking at the code that figure B would always be generated.

 

All help is appreciated!

Link to comment
Share on other sites

To explain: When the object is on the screen your osnaps are active, this if you get the current osmode and set it to variable, then change the osmode to 0 while your program is running, then it will not snap to an object, then you turn it back to what it was.

Link to comment
Share on other sites

A suggestion the changing of osmode is pretty common in lots of situations.

 

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
....
your code
...
(setvar 'osmode oldsnap)

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