Jump to content
SebastianTheCrab

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

Recommended Posts

SebastianTheCrab

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!

Share this post


Link to post
Share on other sites
Commandobill
(setvar 'osmode 0)

Share this post


Link to post
Share on other sites
Commandobill

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.

Share this post


Link to post
Share on other sites
SebastianTheCrab

It worked - thank you!

Share this post


Link to post
Share on other sites
Commandobill

No problem :thumbsup:

Share this post


Link to post
Share on other sites
BIGAL

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)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×