I'm looking to incorporate a LISP command into a dynamic block

I'm looking to incorporate a LISP command into a dynamic block

cclawsonD6QHU
Explorer Explorer
774 Views
31 Replies
Message 1 of 32

I'm looking to incorporate a LISP command into a dynamic block

cclawsonD6QHU
Explorer
Explorer

So I'm very new to LISP Commands and think I have something that will do what I want it to do, however I want it inside a dynamic block that will update as I stretch it, (basically I want to associate a line with a divide command making equal parts at or under 12" on center) I have no idea how to do that, so any help would be greatly appreciated. (the line in question is the gray line with the drill holes on each end)

Attached are both the block and LISP 

thanks

0 Likes
Accepted solutions (1)
775 Views
31 Replies
Replies (31)
Message 2 of 32

Moshe-A
Mentor
Mentor

@cclawsonD6QHU  hi,

 

Post a sample dwg with origin block and 1 or 2 examples beside it stretched so we can understand what do you mean/want?

 

Moshe

 

0 Likes
Message 3 of 32

cclawsonD6QHU
Explorer
Explorer

is this sort of what your asking?

0 Likes
Message 4 of 32

Moshe-A
Mentor
Mentor

@cclawsonD6QHU ,

 

i see you been in Dynamic Block forum and you got an advice to come here but as i see this it could be solved with dynamic block tools

all you need for each pair of lines (hor/ver) is a linear parameter and a stretch action 

and another linear parameter (again for pair) and array action on the last circle (actually two)

 

first on the base block (before it's stretched) scatter the circles along the horizontal lines (equally distance)

than apply the array action on the last 2 circle (1 on each line)

do the same for the vertical

 

that's should do the trick 😀

 

Moshe

 

 

 

 

 

 

0 Likes
Message 5 of 32

cclawsonD6QHU
Explorer
Explorer

not sure I follow... I need it to have a tolerance of no greater than 12" O.C. but maintain equal distances should said panel be something like 2'6" thus making the center 3 equal segments with drill holes 10" O.C. hence the reason for the divide command and Script. as far as I know an array has a set interval it has to be...

Thanks for the help.

0 Likes
Message 6 of 32

Sea-Haven
Mentor
Mentor

Can you post a dwg with multiple panels of say different overall lengths so can see what your trying to do.

 

Eg length 25 so 3 panels = 8.33333 wide. This is a simple divide 25 by 12 = 2.08333 so as has remainder  0.0833 which is > 0.0 so add 1 to the integer ie = 3 required.

0 Likes
Message 7 of 32

cclawsonD6QHU
Explorer
Explorer

Is this what you would like?

0 Likes
Message 8 of 32

Sea-Haven
Mentor
Mentor

I don't do a lot with dynamic blocks, rather just draw what you want as objects blocks lines circles etc, say based on enter height and width. I take it you want more holes added when the line length exceeds 12". That is a dynamic block parameter so I can not help. But the dwg was useful for say others more experienced with dynamic blocks.

0 Likes
Message 9 of 32

Moshe-A
Mentor
Mentor

@cclawsonD6QHU hi,

 

Have a few questions for you 😀

Your drawing is set with Architectural units but you have a thickness attribute which would be in mm?

 

Do you know what annotations is?

Your block is defined as annotative block and has annotation scale of 3"=1'-0" - are you aware of that? annotation scale should be applied to annotation objects like texts, dimensions and blocks or 

symbols that are affected by the change of drawing scale. does your Square panel block is affected by drawing scale?    

i'm asking all that cause say you bring in a Square Panel in at 1'=1' and the drills holes are scattered 12" as you want them, what do you think would happen to the drill holes distance when you apply 3"=1'-0" annotation scale?

 

Moshe

     

0 Likes
Message 10 of 32

Brock_Olly
Collaborator
Collaborator

Moshe is correct you can do this within a block without LISP.
I created a similar block a while ago though the holes are on the inside.


I don't have access to full autocad right now so I cannot edit it though you can see the principle behind it.
You can create an array of your holes on the edge and calculate the required dimensions inside a parameter with named dimensions.

0 Likes
Message 11 of 32

Brock_Olly
Collaborator
Collaborator

Check out this thread, which is where I learned it from, from Ojuris and J Palme.
https://forums.autodesk.com/t5/dynamic-blocks-forum/object-in-dynamic-block-should-be-stretch-equall...

0 Likes
Message 12 of 32

cclawsonD6QHU
Explorer
Explorer

yes I know what annotative does and I always draw these at 3" = 1' as is the standard for the office and should I need to change that it is a simple matter of changing the block scale to what I need and deleting out the old scale. as to the thickness that is the text for the thickness of the panel, and so is just the orange text in the block that tag is called thickness and the text placeholder is MM to remind the drafter that that particular tag needs to be MM.

0 Likes
Message 13 of 32

Moshe-A
Mentor
Mentor

@cclawsonD6QHU 


@cclawsonD6QHU wrote:

yes I know what annotative does and I always draw these at 3" = 1' as is the standard for the office and should I need to change that it is a simple matter of changing the block scale to what I need and deleting out the old scale. as to the thickness that is the text for the thickness of the panel, and so is just the orange text in the block that tag is called thickness and the text placeholder is MM to remind the drafter that that particular tag needs to be MM.


And what do you achieve by scaling the panel to 3"=1'-0"?  assuming your goal is to plot it at that scale but in AutoCAD real Material objects are drawn at 1:1 only annotative objects that may change due to plot scale gets annotation scales.

here is an example:

say your panel is 24" x 24" - ok? if you want it to be fit in A4/A3 sheet size you can plot it at 1"=10" (1:10) scale what you done is the opposite, you reduce the side of a real object in order to keep plot at 1"= 1" this could work only for your Square Panel it will disrupt the real distance of the panel and the real distance between drill holes. also adding linear dimensions will be disrupt - makes sense?

 

Moshe

0 Likes
Message 14 of 32

cclawsonD6QHU
Explorer
Explorer

to be honest with you this is a block someone else made and they asked me to fix it but it's looking like it might just be easier to build a brand new one. they now have to size it explode it then divide command to get the drill holes... I'm totally fine with making it un-annotative so long as the text and dims show up 1/8" in paper space. (using sheet sets)

0 Likes
Message 15 of 32

Moshe-A
Mentor
Mentor

@cclawsonD6QHU ,

 

if the texts and the dimensions is annotative, and you draw them in model 1:1 , you can attach them to the right annotation scale to bring them to be any height in paper space, it is all about working right 😀

 

and again, geometric real objects are always need to be draw at 1:1 scale.

 

Moshe

 

 

0 Likes
Message 16 of 32

cclawsonD6QHU
Explorer
Explorer

gotcha. guess I wasn't paying attention to that sort of thing just started fiddling with his block. thanks.

0 Likes
Message 17 of 32

Moshe-A
Mentor
Mentor
Accepted solution

@cclawsonD6QHU  hi,

 

OK check this program. wrap this code lines in drills.lsp.

also attached sample_panel.dwg, test this on this file, load the lisp

the dwg contains a modified square panel block which is not annotative anymore (and it should stay 😀)

do not try to run this on your existing blocks, simply it will not work

 

Once you stretch the block (by it's dynamic hor/ver grip handles) the drill holes will be scattered - job done 🙏

 

Note:

The first time you insert "square panel" block (still not stretched) it's name is "square panel". once you stretch it, it's name changes to *Unnn

this called Anonymous Block (it's copy of the origin) but AutoCAD know it's derived from origin . my lisp program works on the anonymous block.

manually updating the origin "square panel" (BEDIT \  block edit) all the drill holes are vanished, they are not part of the origin block.

so you need to take care about this. each activation drags regenerating drawing to reflect the change.

 

you can also invoke DRILLS command to scatter drill holes (updating the block)

 

; define some const global
(setq MA:BLKNAME "square panel")
(setq MA:DRILL_LINE_LAYER "guide lines")
(setq MA:DRILL_HOLES_LAYER "+drill holes")

 

the above 3 variables, defines the block name + layers

if you need to change the block name and\or layers, you need to modify these lines.

 

the lisp adds an event (known in AutoLISP as Reactor) to monitor each stretch actions. if lisp is not responding, probably the reactor is not

loaded \ installed. best practice is to close AutoCAD and start over.

 

enjoy

Moshe

 

(vl-load-com) ; load activex support

(defun process_drills (ss1 / clear_existing_drill_holes ; local function
		             adoc blocks ss radius-feet radius-inches AcDbBlkRef bname ; local variables
		             AcDbBlkTblRec AcDbEntity len n p0 p1 p2 d0 AcDbCircle)    ; local variables

 ; clear existing drills holes
 (defun clear_existing_drill_holes (ent / BlkRef bname BlkTblRec)
  (setq BlkRef (vlax-ename->vla-object ent))
  (setq bname (vla-get-name BlkRef))
  (setq BlkTblRec (vla-item blocks bname))

  (vlax-for Entity BlkTblRec
   (if (and
	 (eq (vla-get-objectName Entity) "AcDbCircle")
	 (eq (strcase (vla-get-layer Entity)) (strcase MA:DRILL_HOLES_LAYER))
       )
    (vla-delete Entity)
   )

   (vlax-release-object Entity)
  )

  (vlax-release-object BlkTblRec)
  (vlax-release-object BlkRef)
 );  clear_existing_drill_holes
  
 
 ; here start (process_drills)
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startUndoMark adoc)
  
 (setq blocks (vla-get-blocks adoc))
  
 (setq radius-feet (/ 1 16 12.0)) ; 1/16 inch expressed as feet
 (setq radius-inches (cvunit radius-feet "feet" "inches")) ; convert to inches decimal

 (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))
  (clear_existing_drill_holes ename)
     
  (setq AcDbBlkRef (vlax-ename->vla-object ename))
  (setq bname (vla-get-name AcDbBlkRef))

  (if (eq (strcase (vla-get-effectiveName AcDbBlkRef)) (strcase MA:BLKNAME))
   (progn
    (setq AcDbBlkTblRec (vla-item blocks bname))

    (vlax-for AcDbEntity AcDbBlkTblRec
     (if (and
	   (eq (vla-get-objectName AcDbEntity) "AcDbLine")
           (setq len (vla-get-length AcDbEntity))
	   (> len 2.0)
	   (eq (strcase (vla-get-layer AcDbEntity)) (strcase MA:DRILL_LINE_LAYER))
         )
      (progn
       (if (= len 12)
        (setq n (/ len 12.0))
        (setq n (1+ (fix (/ len 12))))
       )
       
       (setq p0 (vlax-safearray->list (vlax-variant-value (vla-get-startPoint AcDbEntity))))
       (setq p1 (vlax-safearray->list (vlax-variant-value (vla-get-endPoint AcDbEntity))))
       (setq d0 0 step (/ len n))
       
       (while (<= d0 len)
        (setq p2 (polar p0 (angle p0 p1) d0))
        (setq AcDbCircle (vla-addCircle AcDbBlkTblRec (vlax-3d-point p2) radius-inches))
        (vla-put-layer AcDbCircle MA:DRILL_HOLES_LAYER)
        (vlax-release-object AcDbCircle)
        (setq d0 (+ d0 step))
       ); while
	 
      ); progn
     ); if

     (vlax-release-object AcDbEntity)
    ); vlax-for
    
   ); progn
  ); if
   
  (vlax-release-object AcDbBlkTblRec)
  (vlax-release-object AcDbBlkRef)
 ); foreach

 (vlax-release-object blocks)
 (vla-regen adoc acActiveViewport)

 (vla-endUndoMark adoc)
 (vlax-release-object adoc)

 (princ)
); process_drills


; define some const globals
(setq MA:BLKNAME "square panel")			; const
(setq MA:DRILL_LINE_LAYER "guide lines")		; const
(setq MA:DRILL_HOLES_LAYER "+drill holes")		; const


; for manual activate
(defun c:drills (/ ss0)
 (if (setq ss0 (ssget (list '(0 . "insert") (cons '2 (strcat MA:BLKNAME ",`*U*")))))
  (process_drills ss0)
 )
); c:drills


; callback
(defun MA:OnCommandEnded (Reactor cmd^)
 (if (and
       (eq (car cmd^) "GRIP_STRETCH")
       (setq ss (ssget "_P"))
     )
  (c:drills)
 )
); MA:OnCommandEnded


; install Reactor
(if (not MA:cmdReactor)
 (setq MA:cmdReactor (vlr-command-reactor nil '((:vlr-commandEnded . MA:OnCommandEnded))))
)

 

 

Message 18 of 32

cclawsonD6QHU
Explorer
Explorer

You are a hero of great renown and I shall sing your praises! Seriously thank you.

0 Likes
Message 19 of 32

Sea-Haven
Mentor
Mentor

@Moshe-A a great program definitely going to study how the bolt holes are added. I thought about this as a extra choice Drills2 allows entry of width and height plus atts all in one command.

(defun c:drills2 (/ ss0)

;; Set Dynamic Block Property Value  -  Lee Mac
;; Modifies the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; val - [any] New value for property
;; Returns: [any] New value if successful, else nil

(defun LM:setdynpropvalue ( blk prp val )
    (setq prp (strcase prp))
    (vl-some
       '(lambda ( x )
            (if (= prp (strcase (vla-get-propertyname x)))
                (progn
                    (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
                    (cond (val) (t))
                )
            )
        )
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

 (setq wid (getreal "\nEnter Width ") Ht (getreal "\nheight "))
 (Command "-Insert" MA:BLKNAME "S" 1 (getpoint "\nPick point for block ") 0 pause pause pause pause "" "" "" "")
 (setq blk (vlax-ename->vla-object (entlast)))
 (LM:setdynpropvalue blk "Width" wid)
 (LM:setdynpropvalue blk "height" ht)
 (setq ss0 (ssadd))
 (setq ss0 (ssadd (entlast)))
 (process_drills ss0)
 )
); c:drills2

 

 

 

0 Likes
Message 20 of 32

Brock_Olly
Collaborator
Collaborator

Moshe made a wonderful LISP, hats off.
Though I do want to point out this can be done easier with dynamic blocks as I said earlier but since I don't think you took the time to check out the thread I linked I will refer to message 19 in that thread where JPalme posted this block, which is almost exactly what you are after..

In that thread he also explains with videos how to do it yourself.
https://forums.autodesk.com/t5/dynamic-blocks-forum/object-in-dynamic-block-should-be-stretch-equall...

0 Likes