I don't know anything about VBA or autolisp or even macros in ACAD, but I could use something that would place a point at the centroid of a region. Currently, I use the MASSPROP command, and place a point at the coordinates of the centroid. How can I automate this? Can I generate a macro to do this? I'm sure it would be helpful if the centroid coordinates were properties of the region.
TIA
try this out
(defun c:point_centroid (/ region_sset)
(if (setq region_sset (ssget '((0 . "region"))))
(foreach region (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex region_sset))))
(vla-addpoint (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
(vlax-3d-point (vlax-get region 'centroid))
)
)
)
(princ)
)
If one at a time is acceptable for you, it simplifies things:
(defun C:PRC (); = Point at Region Centroid
(command "_.point" (vlax-get (vlax-ename->vla-object (car (entsel))) 'Centroid))
(prin1)
)
Thanks.
I'm so dumb, I don't know what to do with this. Do I create a "button"? Do I need to select the region first? I've never done any lisp programming nor customize my acad environment to run a routine. Pointing me to a place where I can learn would be acceptable if telling me how is too difficult.
TIA
Thanks, but I don't know what to do with this. I tried pasting into my command line both before and after selecting a region, but it appears I need to do more than that.
TIA
@BillAllenSE wrote:
Thanks, but I don't know what to do with this. I tried pasting into my command line both before and after selecting a region, but it appears I need to do more than that.
TIA
Sorry, my mistake, the '_gcen' osnap does not work with regions.
@BillAllenSE wrote:
... I don't know what to do with this. ...
First, Ctrl+C Copy the code to the clipboard, then Ctrl+V Paste it in at the command line in AutoCAD, to define the command. [If it's ending with the final right parenthesis without going back to the Command: prompt, hit Enter to conclude it.] Then type in the command name PRC, and it will ask you to select the Region and will place the Point object.
If that works, we can talk about how to make it more directly available.
I can work with polylines. I just create regions now to do MASSPROP to get the centroid. I'm just looking for a more efficient way of finding and dimensioning the centroid.
Thank you
I entered the following in the command line:
_.point (enter)
_.gcen (enter)
I then hovered over the polyline and it place a point at the cg.
Is there a "macro record" feature in ACAD similar to Excel? If so, I can record this as a macro for later use, because I will never remember this. 🙂
Thank you very much
That didn't work for me. I got a "properties close" function instead. Even though "prc" is not in my alias list, but prclose is.
Change the command name from PRC to something else if you want. Or don't let it autocomplete the command name -- back off the "LOSE" it puts on.
@BillAllenSE wrote:
.....
Is there a "macro record" feature in ACAD ...? ....
It's called the Action Recorder -- the >ACTRECORD command<.
Thank you very much. This looks easy enough that even I might be able to do this.
🙂
The action recorder is a bit limited in that it is not editable in a more complex situation. A failure in a way by Autodesk that they did not do Like Excel and write VBA code for macros. Any experienced lisper will probably not use the macro record, a side note one Cad package did write VBA code as its macro record.
My suggestion is that you save the lisps like the one suggested here in a single location, you can make a Custom lisp that gets loaded every time you start your CAD, I have one called Autoload.lsp, to load it you just do APPLOAD and then save to the "Start up suite".
Ok now what is in your custom lisp is a link to your other Lisps using the "Autoload" function this will demand load your other lisp for you when you type the command name. Here is an example. Also inside Autoload is some 27 defuns or macros like the one here, where they are only a couple of lines long.
(autoload "COPY0" '("COPY0"))
(autoload "COPYCOMMAND" '("ZZZ"))
(autoload "COVER" '("COVER"))
(autoload "DIMFLIP" '("DIMFLIP"))
(autoload "DRAWXFALL" '("DRAWXFALL"))
(autoload "DRAWPIPE" '("DRAWPIPE"))
(autoload "EDITRL" '("EDITRL"))
(autoload "EDITXSECT" '("EDITXSECT"))
(autoload "EDITLSECT" '("EDITLSECT"))
(autoload "FLIPLINE" '("FLIPLINE"))
(autoload "Goto-LAYOUT" '("GOTO"))
Load "Lispname" "commandname"
Also the lisps have been saved in a support path so you can use a short name without the full path being needed.
OPTIONS, FILES, Support paths so add your location of all your saved lisp files. eg D:\CADSTUFF\LISPS.
Options Bricscad, Acad is similar
Happy to help you make a POP menu if you want, hope this information was useful.
A better way as you are probably going to get more and more lisps is to use say a POP menu, these can be made using Notepad and are text files with .mnu file name. They are loaded using Menuload.
This menu made over many years and gets the odd 1-2 addition a year has 100+ lisps behind it.
Thanks, everyone for the help. Not only did I solve my immediate problem (learning the gcen command), but also got some direction to get started in learning to program. I copied the links and put them in my reading list.
Again, thank you all very much for your responses.