Create a fairly simple Lisp for me please.

Create a fairly simple Lisp for me please.

carminatithekid1
Enthusiast Enthusiast
1,506 Views
20 Replies
Message 1 of 21

Create a fairly simple Lisp for me please.

carminatithekid1
Enthusiast
Enthusiast

I am looking to have someone create a fairly simple lisp for me.

 

I am wanting the lisp to allow me to select 2 points, draw a line between those 2 points and I want the line to offset 3" for a 1/4" scale drawing and 6" for an 8th scale drawing. Basically I want the offset to be based upon the dimscale.

I will want the line to be put on a specific layer "MP-NOTE".

I will also want a "DOT" placed at each end of the line. My office already have a lisp for creating this "DOT" and it is called "SPOT"

 

Please and thank you. I know this is simple but I am not educated enough in lisp to build this myself.

 

below is the lisp for "SPOT"

 

;program to build closed donuts in AutoCAD with reference to Dimscale
(defun c:spot (/ dscale spot_od spot_loc) ;start defun, define local variables
(setq dscale (getvar "dimscale")) ;set dscale to current dimscale
(setq spot_od 0.05) ;set dot diameter to .05
(setq spot_od (* dscale spot_od)) ;adjust dot diameter for drawings scale
(repeat 20 ;start repeat
(setq spot_loc (getpoint "\nCenter of doughnut: ")) ;get center of dot
(command ;start command
"laymcur" spot_loc ;change layer to object found at dot center point
"donut" "0" spot_od spot_loc "" ;draw spot
) ;end command
) ;end repeat
(princ) ;quiet exit
) ;end defun

Randy Carminati
0 Likes
1,507 Views
20 Replies
Replies (20)
Message 2 of 21

wispoxy
Advisor
Advisor
O_O The process you're asking for is faster to do by hand than use a lisp routine. I can do all that under 10 seconds. Not sure why you're trying to save time on 10 seconds. Why not just create a hotkey recording.
0 Likes
Message 3 of 21

carminatithekid1
Enthusiast
Enthusiast

I understand, but to create consistency in the office, I have been instructed to create this lisp. I am a fast drafter and can easily draft this as well, but some others may not be as quick. Also the philosophy is, if we can create a button to eliminate 10 seconds, then every time we use it we just saved 10 seconds.

Randy Carminati
0 Likes
Message 4 of 21

wispoxy
Advisor
Advisor
Use the Action Recorder in AutoCAD 🙂
0 Likes
Message 5 of 21

carminatithekid1
Enthusiast
Enthusiast

So I am not 100% familiar with the action recorder. I just used it, saved the file and now how do I change it to a list to be able to modify it?

Randy Carminati
0 Likes
Message 6 of 21

carminatithekid1
Enthusiast
Enthusiast
I meant "LISP" not list.
Randy Carminati
0 Likes
Message 7 of 21

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

I am wanting the lisp to allow me to select 2 points, draw a line between those 2 points and I want the line to offset 3" for a 1/4" scale drawing and 6" for an 8th scale drawing. Basically I want the offset to be based upon the dimscale.

....

I will also want a "DOT" placed at each end of the line. My office already have a lisp for creating this "DOT" and it is called "SPOT"

 

....

For the Line part, how would the side to which the Line is to be Offset be determined?  [EDIT:  I imagine this is an area where the Action Recorder could sometimes "let you down," but an AutoLisp routine could, for example, be made to always Offset in the more upward of the possible directions, regardless of the angle of the Line or in which direction it was drawn.]

 

For the dot part of it, I'd suggest using a dot defined in a drawing file that can be Inserted as a Block in any drawing.  Let's call it dot.dwg, in some shared folder location that's in everyone's Support File Search Path List.  Make the dot there .05 units in diameter, on Layer 0, and Insert it, scaled directly by the DIMSCALE System Variable.  You wouldn't need the spot_od variable at all, and would adjust the (command) part:

 

(command

  "laymcur" spot_loc

  "_.insert" "dot" spot_loc (getvar 'dimscale) "" ""

)

 

Also, if you wanted to move one of the dots, it would have a grip at its insertion point at the center, which Donuts don't -- you'd need to reach for Osnap Center as a basis to move a Donut if it's the center you want to end up somewhere else.  And a Block couldn't be distorted as a Donut could by grabbing a grip and dragging just that grip, rather than the whole Donut, somewhere accidentally.

 

[By the way, you could do this in a more "graceful" way than (repeat 20), if you're interested, that could be ended if you need fewer than 20 by Enter/space rather than requiring Escape as I suspect yours does, and that could go on for any number more than 20 if you ever need that, without reinvoking the command.]

 

Kent Cooper, AIA
Message 8 of 21

carminatithekid1
Enthusiast
Enthusiast

So I am not 100% sure how the offset would work. I am kind of wanting to tweak that aspect of the lisp.

As stated previously, I am not all that great with lisps but I am am ok at tweaking little things here and there to finally arrive at the appropriate end point.

 

As for the dot command, I am all in favor of what you suggested. I will change this, as it was created years before I started at this firm. But how do I ensure that this new command will take the layer of the line I am attaching it to and apply it to the dot?

Randy Carminati
0 Likes
Message 9 of 21

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

So I am not 100% sure how the offset would work. I am kind of wanting to tweak that aspect of the lisp. ....

 

.... how do I ensure that this new command will take the layer of the line I am attaching it to and apply it to the dot?


Operationally, when you do it manually, how would you choose which side to Offset to for Lines running in different directions?  A routine can probably be made to choose the same way for you, if there's something consistent about the criteria.

 

Ensure the Layer in the same way as in your SPOT routine -- I left the LAYMCUR command in my suggested adjustment, which should handle it, provided the dot in the drawing that's being Inserted is on Layer 0 as mentioned.

Kent Cooper, AIA
0 Likes
Message 10 of 21

stevor
Collaborator
Collaborator
Guessing your intentions, is a start: (princ" C:DDL: ") ; (princ " modes: ") (setvar "dimscale" 0.25) (defun c:DDL (/ DSCALE SOD P1 P2 PE DDS CLN AL HPI OPA1 OPA2 OPB1 OPB2 ) ; local variables ; error f here (princ "\n Double Donut Line, 2D, your Ortho, Osnap, .. modes: ") (setq DDS (getvar "dimscale") LOD (cond ((equal DDS 0.25 1e-9) 3.0) ; or .25 of 3" ?? ((equal DDS 0.125 1e-9) 6.0) (t (princ"\n Other Dim Scale: ") (prin1 DDS) (exit) ) ) ) ; setq (if (and (setq P1 (getpoint " Pick P1: ")) (setq P2 (getpoint P1 " P2: ")) ) (progn (GRDRAW p1 p2 1) (setq cln (geTvar "clayer") SOD (* DDS 0.05) ; cur layer, dot dia AL (angle P1 P2) hpi (/ PI 2) OPA1 (polar P1 (+ AL HPI) LOD) OPA2 (polar P2 (+ AL HPI) LOD) OPB1 (polar P1 (- AL HPI) LOD) OPB2 (polar P2 (- AL HPI) LOD) ) ; setq (command "-layer" "m" "MP-NOTE" "") (PRINC" laymcur not used ") (foreach PE (list OPA1 OPA2 OPB1 OPB2 ) ; ends (command "donut" "0" SOD PE "" ) ) ; donuts (command "LINE" OPA1 OPA2 "" ) ; A offsetee (command "LINE" OPB1 OPB2 "" ) ; B (setvar "clayer" CLN) )) (princ) ) ; def Rather small dots...
S
0 Likes
Message 11 of 21

carminatithekid1
Enthusiast
Enthusiast
I see these smiley faces... Why?
Randy Carminati
0 Likes
Message 12 of 21

carminatithekid1
Enthusiast
Enthusiast

Well if I was to do it manually, I would draw a line, then offset based on dimscale. I would assume 3" for 1/4" and 6" for 8th scale. That is probably the best i can assume for at the moment. Maybe even more, I might want it to be 6" for 1/4 scale and 12" for 8th scale. I am unsure as I have to test this to figure it out.

Randy Carminati
0 Likes
Message 13 of 21

wispoxy
Advisor
Advisor
Laughing faces in lisp code always did make things more interesting. 😐
0 Likes
Message 14 of 21

wispoxy
Advisor
Advisor
0 Likes
Message 15 of 21

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
I see these smiley faces... Why?

You can turn off the colon+character emoticons.  See this thread.

Kent Cooper, AIA
0 Likes
Message 16 of 21

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Well if I was to do it manually, I would draw a line, then offset based on dimscale. I would assume 3" for 1/4" and 6" for 8th scale. That is probably the best i can assume for at the moment. Maybe even more, I might want it to be 6" for 1/4 scale and 12" for 8th scale. I am unsure as I have to test this to figure it out.


The dimensional part is easy, once you decide what you want it to be, and can be a single calculation that will work for any scale, not just 1/4" and 1/8" scales.

 

The more challenging part is how a routine would decide to which side to Offset the Line.  If there's no regularity about the circumstances, it can be left for a User pick in each case, but that's a step they would need to take.  If there is anything predictable about it, for example that it should always go in the more upward direction, and [let's say] to the left for a vertical Line, then the User can be spared the need to pick the side each time, which would be an operational simplification as well as a small time-saver.  This kind of figuring is done in a lot of routines that determine, for example, the rotation of Text that aligns with something, so that it will always be in the more readable direction, regardless of the direction of whatever locations or elements the angle is being calculated from.

Kent Cooper, AIA
0 Likes
Message 17 of 21

carminatithekid1
Enthusiast
Enthusiast
I want it to offset in both directions.
Randy Carminati
0 Likes
Message 18 of 21

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
I want it to offset in both directions.

Ah -- that's easy, by turning the Line into a VLA object and using the (vla-offset) function using the positive and negative versions of the same value.  Then there is no pick point to be determined, and the angle of the Line doesn't matter.

 

In your original description, you say you "want a "DOT" placed at each end of the line."  Is that on only the original Line, or also on the Offset ones, or on the Offset ones but not on the original?

Kent Cooper, AIA
0 Likes
Message 19 of 21

carminatithekid1
Enthusiast
Enthusiast

I think I confused the situation. I want (1) line that I will draw across a rectangle duct (the duct is already drawn and not part of this lisp). I want to pick (2) points and have a line drawn between those (2) points. Then I want to line to be extended each direction bases upon the dim scale. And then I want a dot to be placed at each end point of the line that was created.

 

See the picture attached to see what the final product will look like.

 

 

Randy Carminati
0 Likes
Message 20 of 21

Kent1Cooper
Consultant
Consultant

Ah again -- EXTEND rather than OFFSET.

 

As a start, try the attached BeamLineLabel.lsp with its BEAM command, which I use for Lines representing beams and lintels.  Use the WW option [as if from a Wall to another Wall, where the beam Lines get Extended into the wall at both ends], and change the 0.05 in two places to the plotted-on-paper length you want them Extended.  The two points you would give it for a beam are at the face of the wall, so give it the places [on your blue lines?] from which you want the length extension to be taken.

 

It puts in a Text label, and has its own Layer names, etc., but if it otherwise works for you in the Line-drawing-and-Extending aspect, it can be altered easily to use your Layer name, omit the Text and the Post-vs.-Wall options, and add the dots [and presumably change the file and command names].

Kent Cooper, AIA