TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pabac68010 on August 30, 2021, 02:36:27 PM

Title: Looking for Autocad LISP for auto centering.
Post by: pabac68010 on August 30, 2021, 02:36:27 PM
I'm looking for a Lisp to place a specific block in a center of an Area. For example: in a Hall I'd like to place a smoke detector automatically at the center of the hall.

Any Help is really appreciated. TIA.
Title: Re: Looking for Autocad LISP for auto centering.
Post by: ronjonp on August 30, 2021, 03:14:20 PM
Look into the 'geometric center' osnap.

Welcome to TheSwamp :)
Title: Re: Looking for Autocad LISP for auto centering.
Post by: mhupp on August 30, 2021, 07:43:08 PM
Geo center only works with closed polylines. It might be better to use snap to midpoint of 2 points.
If you hold shift + right click when picking the insertion point of the block it will pop up a menu with all the snaps.
Title: Re: Looking for Autocad LISP for auto centering.
Post by: BIGAL on August 30, 2021, 09:18:57 PM
Shift + Right click mouse for options.

This takes advantage of transparent commands. I would have it as part of a library auto loaded lisp on start up.

(defun c:aaa ()(osnap (vlax-curve-getStartPoint (car (entsel))) "gcen"))

eg 1 LINE 'aaa pick closed pline
eg2 -insert blkname 'aaa pick closed pline
Title: Re: Looking for Autocad LISP for auto centering.
Post by: tombu on September 03, 2021, 09:30:51 AM
Lisp I've used for years added macro to Object Snap Cursor Menu:
Code: [Select]
; Middle Object Osnap
; Macro: ^P(or midobj (load "midobj.lsp")(princ))(midobj)
(defun midobj (/ ll ur selection pntlist pnts adoc)
  (setq selection (car (entsel))
          adoc   (vla-get-activedocument (vlax-get-acad-object))
  )
  (vla-getboundingbox (vlax-ename->vla-object selection) 'll 'ur)
  (setq pntlist  (mapcar 'vlax-safearray->list (list ll ur)))
  (list(/(+(caar pntlist)(caadr pntlist))2.0)(/(+(cadar pntlist)(cadadr pntlist))2.0))
)
Title: Re: Looking for Autocad LISP for auto centering.
Post by: pabac68010 on September 03, 2021, 02:36:29 PM
I'm Kind of new to Autocad so I'm not aware of programming. I saw a video on youtube and that dude using some plugins to create this but I hope there might be some LISP Programs for the same. Ill share the Youtube Link Below. PLEASE IGNORE THE AUDIO.

https://www.youtube.com/watch?v=Ew2uDVWJMYo

Title: Re: Looking for Autocad LISP for auto centering.
Post by: BIGAL on September 03, 2021, 09:27:12 PM
We did provide answers, what is missing is place in centre of room, how is the room defined is it a closed area, a hatch pattern, or has openings, in which case just use M2P a built find command middle of 2 points. To many unknowns.

insert bname M2P ......