Trying to create a macro

Trying to create a macro

jsucheckiM6JVK
Explorer Explorer
1,069 Views
20 Replies
Message 1 of 21

Trying to create a macro

jsucheckiM6JVK
Explorer
Explorer

I want click a macro then I can select a line that will create a rectangle 25 inches above that line. Is this possible?

0 Likes
1,070 Views
20 Replies
Replies (20)
Message 2 of 21

paullimapa
Mentor
Mentor

Questions:

1. What are the dimensions of the Rectangle Height & Width?

2. Does it matter if the Rectangle starts at 25" above from one end of the Line vs the other end?

3. What if the LINE is at an angle? 

4. When you say macro is it a menu macro or lisp function?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 21

jsucheckiM6JVK
Explorer
Explorer
The height of the rectangle is 4 inches

The width is whatever the length of the line is.
0 Likes
Message 4 of 21

paullimapa
Mentor
Mentor

Try attached lisp function DrHzRec.lsp save into one of the folders under Options>Files>Support File Search Path.

On AutoCAD command line enter the following:

(load "DrHzRec") 

Then to execute enter:

DrHzRec

Then pick a horizontal LINE and it will draw the Rectangle:

paullimapa_0-1740730386306.png

If you want in the code you can change the offset distance & height of the rectangle here:

  (setq en (ssname ss 0) ; get entity
        ofds 25 ; offset distance
        rech 4  ; height of rectangle
        stptx (getpropertyvalue en "StartPoint/X")
        stpty (getpropertyvalue en "StartPoint/Y")
        stptz (getpropertyvalue en "StartPoint/Z")
        edptx (getpropertyvalue en "EndPoint/X")
        edpty (getpropertyvalue en "EndPoint/Y")
        edptz (getpropertyvalue en "EndPoint/Z")
  )

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 21

jsucheckiM6JVK
Explorer
Explorer
Will this work if the line in vertical or on an angle?
0 Likes
Message 6 of 21

paullimapa
Mentor
Mentor

No only horizontal.
For vertical or at an angle I think I could add in the code a request to pick the side to draw the rectangle. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 21

jsucheckiM6JVK
Explorer
Explorer
That would be amazing. I've used autocad for a long time. Just never
learned how to code or attach codes. I'm a self employed countertop
measurer and I'm trying to learn how to add a button you would say that can
add splashes (rectangle) the length of a line on any angle. Then how i
could change a line into a scribed line. I'd love to pick your brain on how
I can get these made. It would make my job alot easier. Thanks again for
your help.
0 Likes
Message 8 of 21

paullimapa
Mentor
Mentor

Do a screenshot showing what a scribed line is


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 21

jsucheckiM6JVK
Explorer
Explorer
I'm not at my computer right now. Can I send you a dxf file of what I'm
looking to do later today?
0 Likes
Message 10 of 21

paullimapa
Mentor
Mentor

sure you can post that here when you're ready.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 21

paullimapa
Mentor
Mentor

Here's a revised version I call DrSdRec.lsp which is actually modified from another thread.

DrSdRec now lets you pick a side and supports LINEs drawn at any angle.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 21

Sea-Haven
Mentor
Mentor

Another 

 

 

; very simple offset a line a distance and make a rectang
; By Alan H Feb 2025

; you select an end and the offset will always be to the left

(defun c:lrect ( / ent ename 

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

(setq ent (entsel "\nPick line near left end "))
(setq off (getreal "\nEnter offset "))
(setq ename (car ent))
(setq pt (cadr ent))
(setq entg (entget (car ent)))
(setq pt1 (cdr (assoc 10 entg)))
(setq pt2 (cdr (assoc 11 entg)))
(setq d1 (distance pt pt1))
(setq d2 (distance pt pt2))
(if (> d1 d2)
 (setq tmp pt1
 pt1 pt2
 pt2 tmp)
)
(setq ang (+ (angle pt1 pt2) (/ pi 2)))
(setq pt3 (polar pt2 ang off))
(setq pt4 (polar pt1 ang off))

(command "Pline" pt1 pt2 pt3 pt4 "C")
;(command "erase" ename "")

(setvar 'osmode oldsnap)
(princ)
)

 

 

 

An advanced answer, enter values or can be preset then pick say bottom left point.

SeaHaven_0-1740799049049.png

 

0 Likes
Message 13 of 21

jsucheckiM6JVK
Explorer
Explorer

Thanks again for all your help

0 Likes
Message 14 of 21

paullimapa
Mentor
Mentor

I see that the WHITE LINES are all individual segments.

paullimapa_0-1740849558880.png

If I did this manually I would:

First join them together as a single PLINE 

Next OFFSET it 3/8" picking the side needed

Then go back and draw the dog ears TRIMMING the PLINE back 3"

paullimapa_1-1740849772961.png

Not sure how this can be done with lisp...perhaps @Sea-Haven might have a thought?

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 15 of 21

jsucheckiM6JVK
Explorer
Explorer

I've always done it manually by offsetting. I'd love to create commands that could do what I'm trying to accomplish. Example if one side ( left dog ear ) could be created then it could turn the white line red and create a new dog ear line that was scribed. I've seen other programs able to do this, just not seen it in autocad. 

0 Likes
Message 16 of 21

jsucheckiM6JVK
Explorer
Explorer

In the program I've seen. Create one command called one dog ear. A rectangle you would click the one ear command, after you would select all the lines (lets say 3) you want offset the 3/8" then I would select the side I want it to start at. The last or end of the rectangle would have a 3/8 gap or opening. 

Does this help?

0 Likes
Message 17 of 21

Sea-Haven
Mentor
Mentor

I think something like pick 1st line/pline segment. Dog ear yes/no, pick next segment, dog ear end yes/no, pick segment and so on. One case is a single line others two minimum.

 

Maybe making it a pline will help. Needs a bit of thought but I think can be done. I did something like this for another task offset a line pick next line offset then fillet. 

 

This is just a sub function about getting direction of a pline segment. Based on pick end. May need to use, I think I got original code from Lee-mac.

 

 

(defun getplineseg (ent /  ename param preparam postparam)
  (setq ename (car ent))
  (setq pt (cadr ent))
  (setq pt (vlax-curve-getClosestPointTo ename pt))
  (setq param (vlax-curve-getParamAtPoint ename pt))
  (setq preparam (fix param))
  (setq postparam (1+ preparam))
  (setq pt1 (vlax-curve-getPointAtParam ename preparam)
    pt2 (vlax-curve-getPointAtParam ename postparam)
  )
 (setq d1 (distance pt pt1))
 (setq d2 (distance pt pt2))
  (if (> d1 d2)
   (setq tmp pt1
   pt1 pt2
   pt2 tmp)
  )
  (princ)
)

 

SeaHaven_0-1740887119732.png

 

 

0 Likes
Message 18 of 21

jsucheckiM6JVK
Explorer
Explorer

How do I create this into a lisp?

0 Likes
Message 19 of 21

Sea-Haven
Mentor
Mentor

Getting there just be patient have the two ends working and skip, just need to fillet the objects.

SeaHaven_0-1740962063175.png

 

 

0 Likes
Message 20 of 21

jsucheckiM6JVK
Explorer
Explorer
Thanks again, what you guys do is very hard work. I've been trying to learn
and it's very hard if you don't code for a living. You guys are amazing.
0 Likes