Jump to content

Inserting a Dynamic Block and Setting its attributes, parameters and visibility state


pearldrumbum

Recommended Posts

Hello,

 

I'm new here and not a lisp programmer, but alas, I've been tasked with getting a new system for my company working to compliment our workflow.

 

What I have is a template file that contains only one dynamic block - but it has potentially thousands of different variations.

 

I've gotten as far as getting the block inserted in it's default state with the following:

 

(defun C:tblk(); will have 5 parameters used to modify block attributes
 (command "attreq" "0")
 (command "-insert" "io")
 (command "s" "1" "r" "0")
 )

This is probably extremely simplistic, but so far it does what I want it to do (insert the block and let the user pick an insertion point, but bypass the ability to change scaling and rotation manually).

 

The next step is selecting the last inserted block and setting the block's attributes and visibility state. This block has 50 visibility states (all in one parameter, "Visibility1" simply named 1-50), and potentially up to 104 attributes to set. The values for all these variables will be read from a .csv file that is chosen using a bit of lisp and dcl that I've already written and have working properly. Eventually these values will be passed into this function as 3 strings and 2 lists of strings.

 

I'm not really sure where to go from here, though. Everything I've found via the google machine seems a lot more complicated than what I'm trying to do. Yes, that's a lot of potential variants, but it's actually a fairly simple block.

 

things to keep in mind are -

-There will be many instances of this block within one project, all with different amounts and values of attributes

-I'd also like to be able to insert each with a unique ID that I can reference later (I'm guessing they already have one, but I don't know how to access, change, or reference it later)

 

Should I completely change my approach, or am I on the right track? How can I accomplish the next set of tasks?

 

thanks!

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • pearldrumbum

    12

  • iconeo

    9

  • Lee Mac

    2

  • jonathann3891

    1

Thank you for the responses guys.

 

@jonathann - What is the reasoning behind those changes? I'm new to lisp and learning on the fly. I tried your code and it works the same in practice, so I'm just wondering what the benefit is (in the interest of learning and understanding).

 

@iconeo - That is an incredibly helpful link. Thank you! I've actually stumbled across it in my searches but I wasn't sure how to implement those functions. In the 'Set Dynamic Block Property Value' function - what is the program expecting for the blk argument? It says it's a VLA dynamic block reference object, which sounds to me like an ID of sorts for the specific block. But how do I get the reference object for the last placed block?

Link to comment
Share on other sites

How do I get the VLA Dynamic Block Reference object for the most recently inserted block so I can use it in Lee's setdynpropvalue function, and is it unique to each instance of the block?

Link to comment
Share on other sites

Awesome! thanks for the quick replies, guys. Out of curiosity, is it possible to customize or set the block reference object to something of my liking? I could see some usefulness for this in creating reports later on...

Link to comment
Share on other sites

Perhaps.

 

(setq myblock (vlax-ename->vla-object (entlast)))

 

Then your VLA reference should just be myblock right? I haven't tested this to see if it works.

Link to comment
Share on other sites

I'm having some issues implementing the setdynpropvalue function.

 

(setq lastBlock (vlax-ename->vla-object (entlast)))
(setdynpropvalue ( lastBlock "Visibility1" "4")

is throwing error: bad argument type lentityp nil

 

From what I understand, this means it's recieving nil instead of a vla-object, but why?

Link to comment
Share on other sites

I'm having some issues implementing the setdynpropvalue function.

 

(setq lastBlock (vlax-ename->vla-object (entlast)))
(setdynpropvalue ( lastBlock "Visibility1" "4")

 

is throwing error: bad argument type lentityp nil

 

What am I doing wrong?

 

Does this work?

 

(LM:SetVisibilityState (vlax-ename->vla-object (entlast)) "4")

Link to comment
Share on other sites

Attached .dwg is blank with one block in it. Code below

 

(defun C:tblk(); will have 5 parameters used to modify block attributes
 (setq oattreq (getvar 'attreq))
 (setvar 'attreq 0)
 (command "_insert" "IO")
 (command "S" "1" "R" "0")
 (setvar 'attreq oattreq)

;  (LM:setdynpropvalue ( (vlax-ename->vla-object (entlast)) "Visbility1" "4")
 (LM:SetVisibilityState ( (vlax-ename->vla-object (entlast)) "4")

)

;; 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)
   )
)


;; Set Dynamic Block Visibility State  -  Lee Mac
;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; blk - [vla] VLA Dynamic Block Reference object
;; val - [str] Visibility State Parameter value
;; Returns: [str] New value of Visibility Parameter, else nil

(defun LM:SetVisibilityState ( blk val / vis )
   (if
       (and
           (setq vis (LM:getvisibilityparametername blk))
           (member (strcase val) (mapcar 'strcase (LM:getdynpropallowedvalues blk vis)))
       )
       (LM:setdynpropvalue blk vis val)
   )
)

LDT.dwg

Link to comment
Share on other sites

(defun C:tblk(); will have 5 parameters used to modify block attributes
 (setq oattreq (getvar 'attreq))
 (setvar 'attreq 0)
 (command "_insert" "IO" "S" "1" "R" "0" PAUSE)
 (setvar 'attreq oattreq)
 (LM:SetVisibilityState (vlax-ename->vla-object (entlast)) "4")
)

 

I think you just needed to exit the INSERT command gracefully. I added the PAUSE in there which waits for your mouseclick then continues with the LISP.

 

Also, you had one too many sets of parens in the Lee Mac call.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...