Visual LISP, AutoLISP and General Customization

Reply
Active Member
caddnima
Posts: 10
Registered: ‎01-07-2014
Message 1 of 17 (465 Views)
Accepted Solution

HELP WITH INSERTING DYNAMIC BLOCK?

465 Views, 16 Replies
01-07-2014 09:24 PM

Hello to all,

 

I have been a long time lurker but first time poster. I need help with Dynamic Block. I cannot wrap my head about VLISP thats why I am here hoping that maybe someone can point me to the right direction.

 

Please see attached file. Inside the file you will find the dynamic block in question.

 

Problem : 

1) I dont know how to disect the dynamic block. If its a regular entity or block, we can simply check the dxf group and simply edit it.  But with dynamic block, I cannot find the DXF group to edit.

2) I think I can say Im pretty good (not expert) with LISP but beyond that, Im totally DUMB. I dont know anything about VLISP and beyond.

3) When someone says dynamic block state, im totally clueless. Then there is this FLIPPED? If someone will check the dynamic block, there is the FLIP, then the OPTION then the TAIL LENGTH.

 

Conditions : This routine needs to happen fully automatic, no user intervention, so no dialog boxes, no prompts for what OPTION to use. Everything will be controlled with conditions and ifs.

 

History/Process :

 

 

The drawings will be coming off/export from REVIT. 

The dwg will contain regular blocks. Ex Elevation callout, Section Callout, Detail Callout.

 

The routine will do....

a) Open the dwg file. (I can do this)

b) Look for certain (non-dynamic) blocks, ie: elevation, section, callouts...(I can do this)

 

c) If the block is elevation block, then insert dynamic block, and then change the option to elevation. (need help on this)

 

I believe that If someone can point me or help me do one task like the one above, I can do the rest.

 

I tried several LISP, VLISP functions by LEE MAC from his websites but Im totally clueless on how to invoke them.

This is the first time i see a function other than c:.  Lee's functions are all with LM:. I dont know where to begin.

 

I hope I was clear explaining the situation and I know this subject have been asked so many times in this forum. 

I just thought that it would be easier to ask and create a new thread instead of trolling and wasting time figuring why I cant understand a thing about it.

 

Thank you in advance.

 

CT

 

 

 

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 2 of 17 (455 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-07-2014 10:02 PM in reply to: caddnima

caddnima wrote:

Hello to all,

 

The drawings will be coming off/export from REVIT. 

The dwg will contain regular blocks. Ex Elevation callout, Section Callout, Detail Callout.

 

The routine will do....

a) Open the dwg file. (I can do this)

b) Look for certain (non-dynamic) blocks, ie: elevation, section, callouts...(I can do this)

 

c) If the block is elevation block, then insert dynamic block, and then change the option to elevation. (need help on this)

 

Thank you in advance.

 

CT 

 


Show us what you have  so far CT and we'll pick up from there.

 

Active Contributor
aliensinearth
Posts: 31
Registered: ‎09-02-2013
Message 3 of 17 (438 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-07-2014 11:47 PM in reply to: caddnima
Spoiler
CopyPaste the below code or download my attachment and run.
Spoiler
Give me the feedback if it solved your purpose or not.

 

(defun c:IDB (/ os pt vlae prop prop_list x)
  
  (command "ucs" "w")
  (setq os (getvar 'osmode))
  (setvar "attreq" 0)
  (setvar "osmode" 0)
  
  (setq pt (getpoint "\nPick Insertion point : "))

  (command "_.Insert" "GS-ViewCallout" pt "1" "" "0")

  (setq vlae	  (vlax-ename->vla-object (entlast))
	prop	  (vla-getdynamicblockproperties vlae)
	prop	  (vlax-variant-value prop)
	prop_list (vlax-safearray->list prop)
  )

  (foreach x prop_list
	    (if	(= (vla-get-propertyname x) "OPTION")
	      (vla-put-value x "Elevation") ;; You can change here for another option
	    )
  )

  (command "ucs" "p")
  (setvar "osmode" os)
  (setvar "attreq" 1)
  (princ)
)

 

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 4 of 17 (429 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-08-2014 12:26 AM in reply to: caddnima

caddnima wrote:

 

Conditions : This routine needs to happen fully automatic, no user intervention, so no dialog boxes, no prompts for what OPTION to use. Everything will be controlled with conditions and ifs.

 

 

c) If the block is elevation block, then insert dynamic block, and then change the option to elevation. (need help on this)

 

 


What will be the insertion point for the block?

Attribute Value?

 

 

EDIT:

(defun c:demo (/ ref blk e state)
  (if
    (and (setq ref (vl-some '(lambda (nme)
			       (if (ssget "_X"
					  (list	'(0 . "INSERT")
						'(410 . "MODEL")
						(cons 2 nme)
					  )
				   )
				 nme
			       )
			     )
			    '("Ref_Elevation" "Ref_Section");<--- change the name to match your target block names
		   )
	 )				;<--- your block names
	 (tblsearch "BLOCK" "GS-ViewCallout")
	 (setq state (cadr (assoc ref
				  '(("Ref_Elevation" "Elevation");<-- the second elemet is the equivalent vis state per block
				    ("Ref_Section" "Section Cut")
				   )
			   )
		     )
	 )
;;; You can remove this line if you have a specific spot for insertion point 	;;;
	 (setq p (getpoint "\nPick Insertion Point:"))
;;;	 									;;;
    )
     (progn
       (setq blk (vlax-invoke
		   (vlax-get (vla-get-ActiveLayout
			       (vla-get-activedocument
				 (vlax-get-acad-object)
			       )
			     )
			     'Block
		   )
		   'InsertBlock
		   p
		   "GS-ViewCallout"
		   1
		   1
		   1
		   0
		 )
       )
       (if (and
	     (LM:getvisibilityparametername blk)
	     (/= state (LM:GETVISIBILITYSTATE blk))
	   )
	 (progn
	   (LM:SetVisibilityState blk state)
;;;	This is the spot where you will assign the attribute value	;;;
	   (foreach itm	(vlax-invoke blk 'GetAttributes)
	     (if (setq v
			(assoc (vla-get-tagstring itm)
			       '(("VIEW_ID" "Value") ("FROM_DWG#" "ThatDwg"))
			)
		 )
	       (vla-put-textstring itm (cadr v))
	     )
	   )
;;;									;;;
	 )
       )
     )
     (princ "\nIncomplete Data")
  )
  (princ)
)

 

You need to download the following functions from Lee Macs website

 

LM:getvisibilityparametername
LM:smileyfrustrated:etVisibilityState
LM:GETDYNPROPVALUE
LM:GETDYNPROPALLOWEDVALUES
LM:smileyfrustrated:ETDYNPROPVALUE

 

HTH

 

 

Mentor
bhull1985
Posts: 431
Registered: ‎07-17-2013
Message 5 of 17 (411 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-08-2014 04:16 AM in reply to: pbejse

An alternate, credits to CAB @ theswamp.org

This would just handle the dyn block insertion, you'd need to incorporate this into your larger routine or frankly, just use pbejses :smileyhappy:

But for if any reason you need an alternate, here's one....

 

;;; Function to insert block with Dynamic Parameters Set
(vl-load-com) ;Load VLisp extensions
;;; Use example:
;;;   (InsDynBlock "door-s" '(("Angle" . 120.0) ("Visibility" . "D")))
;;;
(defun InsDynBlock (bName params / en eo paramCol p v)
  (command "_.INSERT" bName) ;Start Insert command
  (while (> (getvar "CMDACTIVE") 0) (command pause)) ;Let user pick points, scale, rotation
  ;; Check if no error occured, e.g. wrong block
  (if (and (setq en (entlast)) ;Get last entity
           (setq eo (vlax-ename->vla-object en)) ;Convert to COM object
           (= (vla-get-ObjectName eo) "AcDbBlockReference") ;Check if block
           (= (strcase (vla-get-EffectiveName eo)) (strcase bName)) ;Correct block
           (setq paramCol (vla-GetDynamicBlockProperties eo)) ;Get the parameters
           (setq paramCol (vlax-variant-value paramCol)) ;Convert variant to SafeArray
           (>= (vlax-safearray-get-u-bound paramCol 1) 0) ;Check if there are parameters
           (setq paramCol (vlax-safearray->list paramCol)) ;Convert to list
      ) ;_ end of and
    (progn
      (foreach p paramCol ;Step through list
        ;; Check if current parameter is to be set
        (if (setq v (assoc (vla-get-PropertyName p) params)) ;Get the value
          (cond
            ((= (vla-get-UnitsType p) 0) ;String
             (vla-put-Value p (vlax-make-variant (cdr v) vlax-vbString)) ;Set the value
            )
            ((= (vla-get-UnitsType p) 1) ;Angle
             (vla-put-Value p (vlax-make-variant (* (/ (cdr v) 180.0) pi) vlax-vbDouble)) ;Set the value
            )
            ((= (vla-get-UnitsType p) 1) ;Distance
             (vla-put-Value p (vlax-make-variant (cdr v) vlax-vbDouble)) ;Set the value
            )
          ) ;_ end of cond
        ) ;_ end of if
        (vlax-release-object p) ;Release the COM object handle
      ) ;_ end of foreach
      (vlax-release-object eo) ;Release the COM object handle
    ) ;_ end of progn
    (princ "\nSome error occured, could not insert or set parameters.")
  ) ;_ end of if
  (princ)
) ;_ end of defun

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Active Member
caddnima
Posts: 10
Registered: ‎01-07-2014
Message 6 of 17 (393 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-08-2014 08:02 AM in reply to: caddnima

Thank you all for the help.  I will begin by disecting all your routines starting from the top and down.

 

I will start with aliensinearth. Looks simple enough. I will copy and paste it and report back.

 

CT

Active Member
caddnima
Posts: 10
Registered: ‎01-07-2014
Message 7 of 17 (386 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-08-2014 08:24 AM in reply to: caddnima
@aliensinearth,

I dont know why your code is so simple, but it worked.
Active Member
caddnima
Posts: 10
Registered: ‎01-07-2014
Message 8 of 17 (374 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-08-2014 09:28 AM in reply to: caddnima

This is for me so i can review this in the future, but please feel free to correct me.

 

Lets disect it line by line.

 

(command "_.Insert" "GS-ViewCallout" pt "1" "" "0")

 What is "_.Insert". what I mean is, what is the "_." does?

 

 

 

(setq vlae	  (vlax-ename->vla-object (entlast))
	prop	  (vla-getdynamicblockproperties vlae)
	prop	  (vlax-variant-value prop)
	prop_list (vlax-safearray->list prop)
  )

 So bottom line is we need to find the "prop_list"

 

 

(foreach x prop_list
	    (if	(= (vla-get-propertyname x) "OPTION")
	      ;(vla-put-value x "Elevation") ;; You can change here for another option
		  (vla-put-value x "Section Cut")
	    )
  )

 Then we have to look for each entry inside that list and see if there is a property name "OPTION"

All this time, I have been trying to put the value of OPTION which is ie: Elevation. totally wrong in my part, thats why it wont work.

 

 Then we have to assign a new value in "vla-put-value" to what ever we want it to be, ie: "Section Cut"

 

I think I got it?

 

Thank you 

 

CT

 

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 9 of 17 (349 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-08-2014 06:56 PM in reply to: caddnima

caddnima wrote:

Thank you all for the help.  I will begin by disecting all your routines starting from the top and down.

 

CT


Reason the code i posted doesnt look as "simple" as the rest is the code incorporated catching the current "(non-dynamic) block" status and the capablity to fill up the attribute values. Notice that nowhere in the code you will see a test for a specifc parameter name. <Option> . Since you mentioned on your first post that  <<<I tried several LISP, VLISP functions by LEE MAC from his websites but Im totally clueless on how to invoke them.....I dont know where to begin.>>>  Hence the posted code

 

Hope somebody else can find a use for this code. 

 

Active Contributor
aliensinearth
Posts: 31
Registered: ‎09-02-2013
Message 10 of 17 (341 Views)

Re: HELP WITH INSERTING DYNAMIC BLOCK?

01-08-2014 09:25 PM in reply to: caddnima

//So bottom line is we need to find the "prop_list"//

Yes. Exactly.
Now you got it. you can play around in Dynamic Blocks like this.


As pbejse has mentioned. I haven't included any error checking code. Since you know to write the program, please include error checking codes before giving to others.

 

//What is "_.Insert". what I mean is, what is the "_." does?//

 

"_" means, Irrespective of any local language, Autocad will override to English (for commands).

"." means, Even if you have Undefined the "Insert" command, adding "." before the command name will make command work.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community