lisp to draw xlines

lisp to draw xlines

samspade
Advocate Advocate
1,656 Views
8 Replies
Message 1 of 9

lisp to draw xlines

samspade
Advocate
Advocate

I am trying to write a lisp that will draw multiple xlines on a specified layer. I was able to create one to change to the layer I want and draw a vertical or horizontal xline, then change back the layer, but I would like it to not change back the layer until the user has created as many lines as they want to. I have been trying for several hours but cannot figure out how to get this to work.

thanks in advance for any help...

 

thanks

0 Likes
Accepted solutions (3)
1,657 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

Check out ConstLines.lsp with its RX command, here.  It will do what you're after and more.

Kent Cooper, AIA
0 Likes
Message 3 of 9

samspade
Advocate
Advocate

Kent,

 

thanks for sharing. I was hoping to be able to understand the part that allows the user to keep creating lines but was unable to sort that out. I see how much your command does, but I was hoping for something a little less. we don't use rays and I wanted to be able to have XV and XH to be all you needed to get the result.

 

I will continue trying to sort it out, I am just not very often writing lisp so pretty uneducated....

 

thanks!!

0 Likes
Message 4 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@samspade wrote:

.... I was hoping to be able to understand the part that allows the user to keep creating lines but was unable to sort that out. I see how much your command does, but I was hoping for something a little less. we don't use rays and I wanted to be able to have XV and XH to be all you needed to get the result.

....


You can simply ignore its Ray capability and its other-than-orthogonal specified-Angle options.  Its initial default is Xlines [so that starts you off unencumbered by the Ray possibility], in Free direction [like the regular Xline command].  Start the RX command, and just type an H to make Horizontal Xlines, and pick as many locations as you want, through each of which a horizontal Xline will be drawn, and type a V to switch to Vertical ones, and back and forth between the two directions as often as you like, all within one running of the command -- no need for separate XV or XH commands, or to get out of one of them and into the other to switch directions.  End it with Enter/Space/Escape, and it will return the current Layer to what it was before you started.

Kent Cooper, AIA
Message 5 of 9

stevor
Collaborator
Collaborator
Did not see XV or XH in Kent's routine, so what are you referring to? And why not just say what you want in the routine? For example, change reference point and retain the slope, or vice verse; or change all? And post your routine, so that someone may build on that.
S
0 Likes
Message 6 of 9

samspade
Advocate
Advocate

Thank you so much! I will be using it... have a great day. I marked it as solution and gave kudos, much deserved.

0 Likes
Message 7 of 9

samspade
Advocate
Advocate

I am admittedly not a big lisp writer so, fearing my code was a little, eh, awkward, I was hesitant to show it. plus it had really devolved into a state after trying all my ideas. I kinda wanted something a little general so I could apply the idea to any other codes I might try my hand at in future. In the end, I am going with Kent's original post.

 

thanks!

0 Likes
Message 8 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

@samspade wrote:

I am admittedly not a big lisp writer so, fearing my code was a little, eh, awkward, I was hesitant to show it. plus it had really devolved into a state after trying all my ideas. I kinda wanted something a little general so I could apply the idea to any other codes I might try my hand at in future. In the end, I am going with Kent's original post.

 

thanks!


We all were started somehow... here is very simple code to learn from.

 

See...

- command keeps running until user says not to.

- routine creates new layer if does not exists yet.

- routine returns previous current layer even if the command is ended "dirty" by hit ESC key.

 

(defun c:xh ( / *error* oCLAYER )
  
  ;----- This will reset current layer in case of error or hit ESC.
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'clayer oCLAYER)
    (princ))


  
  (setq oCLAYER (getvar 'clayer))
  (command "_LAYER" "_M" "MyLayer" "_C" 5 "MyLayer" "")  ; It creates MyLayer in case does not exist, always makes the layer current

  (command "_.XLINE" "_H")
  (while (> (getvar 'CMDACTIVE) 0)
    (command PAUSE))

  (setvar 'clayer oCLAYER)
  (princ)
)

 

Message 9 of 9

scot-65
Advisor
Advisor
Accepted solution
>>I kinda wanted something a little general so I could apply the idea to any other codes I might try my hand at in future

There are two ways to attack the tailoring of objects.
a) Change the environment then create the object.
b) Let AutoCAD create the object in the default environment and tailor
the object to have the appropriate characteristics.

I favor the later.

In concept, for a repeating command, prompt the user for a selection
point as the WHILE argument. If it is true, create the object and either
use CHPROP or ENTMOD using either "Last" or ENTLAST. What this does
is minimize error handling and the possibility of the environment from
being out of alignment. Layer and linetype will require checking/loading
but other than that, it is pretty foolproof.

FYI: I do have XH and XV as well as XHD/XHD (Defpoints) as well as
coloring the XLines XH1...XV10.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.