Author Topic: Looking for Autocad LISP for auto centering.  (Read 1644 times)

0 Members and 1 Guest are viewing this topic.

pabac68010

  • Mosquito
  • Posts: 2
Looking for Autocad LISP for auto centering.
« 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.
« Last Edit: August 30, 2021, 02:41:18 PM by pabac68010 »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Looking for Autocad LISP for auto centering.
« Reply #1 on: August 30, 2021, 03:14:20 PM »
Look into the 'geometric center' osnap.

Welcome to TheSwamp :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

mhupp

  • Bull Frog
  • Posts: 250
Re: Looking for Autocad LISP for auto centering.
« Reply #2 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.
« Last Edit: August 31, 2021, 07:47:04 AM by mhupp »

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Looking for Autocad LISP for auto centering.
« Reply #3 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
A man who never made a mistake never made anything

tombu

  • Bull Frog
  • Posts: 288
  • ByLayer=>Not0
Re: Looking for Autocad LISP for auto centering.
« Reply #4 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))
)
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

pabac68010

  • Mosquito
  • Posts: 2
Re: Looking for Autocad LISP for auto centering.
« Reply #5 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


BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Looking for Autocad LISP for auto centering.
« Reply #6 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 ......
A man who never made a mistake never made anything