pearldrumbum Posted September 29, 2015 Share Posted September 29, 2015 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! Quote Link to comment Share on other sites More sharing options...
jonathann3891 Posted September 29, 2015 Share Posted September 29, 2015 I would set attreq like this: (setq oattreq (getvar 'attreq) (setvar 'attreq 0) (command "_insert" "IO") (command "S" "1" "R" "0") (setvar 'attreq oattreq) Lee Mac has an "Update Titleblock Attribute" lisp that reads a csv. http://www.lee-mac.com/updatetitleblock.html Quote Link to comment Share on other sites More sharing options...
iconeo Posted September 29, 2015 Share Posted September 29, 2015 This is what you need to control the dynamic block properties. http://www.lee-mac.com/dynamicblockfunctions.html Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted September 29, 2015 Author Share Posted September 29, 2015 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? Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted September 29, 2015 Author Share Posted September 29, 2015 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? Quote Link to comment Share on other sites More sharing options...
iconeo Posted September 29, 2015 Share Posted September 29, 2015 LOL. I had to ask Lee the same question. This should get you there. (vlax-ename->vla-object (entlast)) Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted September 29, 2015 Author Share Posted September 29, 2015 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... Quote Link to comment Share on other sites More sharing options...
iconeo Posted September 29, 2015 Share Posted September 29, 2015 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. Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted September 29, 2015 Author Share Posted September 29, 2015 Oh. Right. Quote Link to comment Share on other sites More sharing options...
iconeo Posted September 29, 2015 Share Posted September 29, 2015 Are the 50 visibility states for each of the States? Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted September 30, 2015 Author Share Posted September 30, 2015 No they aren't. They're just lines of text Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 30, 2015 Share Posted September 30, 2015 Thanks for the recommendations guys, I'm glad it helps. Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted September 30, 2015 Author Share Posted September 30, 2015 Thanks for the recommendations guys, I'm glad it helps. Thank YOU, Lee, for all you do to help us newbies out! Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted October 1, 2015 Author Share Posted October 1, 2015 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? Quote Link to comment Share on other sites More sharing options...
iconeo Posted October 1, 2015 Share Posted October 1, 2015 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") Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted October 1, 2015 Author Share Posted October 1, 2015 Does this work? (LM:SetVisibilityState (vlax-ename->vla-object (entlast)) "4") That is also returning the same error Quote Link to comment Share on other sites More sharing options...
iconeo Posted October 1, 2015 Share Posted October 1, 2015 Can I see the full code along with the block? Quote Link to comment Share on other sites More sharing options...
iconeo Posted October 1, 2015 Share Posted October 1, 2015 Are you sure that the entlast is indeed the dynamic block? Quote Link to comment Share on other sites More sharing options...
pearldrumbum Posted October 1, 2015 Author Share Posted October 1, 2015 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 Quote Link to comment Share on other sites More sharing options...
iconeo Posted October 1, 2015 Share Posted October 1, 2015 (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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.