Jump to content

Recommended Posts

Posted

Hi Everybody,

 

I need some help with my AutoLISP script. I work for a decking company and am trying to streamline some of our layout procedures.

 

The problem I'm having is that when the program enters my loop, it doesn't work correctly. Every loop interation is supposed to increment the x and y values slightly, exactly like an array. The array cycles correctly for all interations, but it will not draw the lines in the proper spots. For example a line of length 10000 with a deck size of 500 should have 20 interations, and therefore 20 lines layed out like an array. It preforms the loop 20 times, but does not draw 20 lines at the points where it's supposed to. I've checked that the line values are being incremented correctly and they are, it has to be a problem with the way I'm using the line command or something.

 

I've attached the lsp file and a drawing with some lines to select to see what I mean. Any help would be great, I'm stumped.

 

deckLines.lsp

deckTest.dwg

Posted

Only took a quick look at your code, but since you are using the (command) function to draw the lines, make sure that object snaps are disabled. My guess is that a running snap is on and the lines you are drawing are snapping to something else instead of going to the coordinate provided.

Posted

I got the program to work fine. I think your problem may be the direction that each of the lines are drawn. In the graphic below, the drawing on the left had the lines drawn in the same direction. The one on the right, one was drawn right to left and the other left to right.

 

dl.png

Posted

Thank you both for your replies, the problem I was having was the OSNAPs - I hadn't even considered the other issue but that's something I'm going to have to address now too.

Posted (edited)

I put this into nearly every lisp I do

 

(setq oldsnap (getvar "osmode"))
(setvar "osmode" 0)


;;;at end 
(setvar "osmode" oldsnap)

Edited by rkmcswain
add CODE tags
Posted
I put this into nearly every lisp I do

 

(setq oldsnap (getvar "osmode"))
(setvar "osmode" 0)
;;;at end 
(setvar "osmode" oldsnap)

 

It's good to have an error handler too in case the routine ends before that last line executes, but if you don't, then you should consider just turning off object snap instead of setting the value of osmode to 0. This way, if the last line never executes, the object snap settings are not lost.

 

;;; example from http://forums.autodesk.com/t5/AutoCAD-2011/Aperture-Box-and-OSMODE/m-p/2673449#M1148

;;; turns off running snaps
(setvar "OSMODE" (logior (getvar "OSMODE") 16384))

;;; restores running snaps
(setvar "OSMODE" (logand (getvar "OSMODE") (~ 16384)))


Posted

I can't tell you how many times I've had issues with osnaps fouling up my LISPs (ok well, technically the reverse...). At first I turned them off within the code, but with so many different people in my office using so many different versions of AutoCAD, and each version tweaked to their personal preferences, not to mention my own inexperience, I had a lot of errors in my code which meant the osnaps turned off and stayed off. The error handling was nice, but I kept forgetting to put that into my code.

 

My solution: mash F3 before running a LISP. :|

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