change visibility state of dynamic block with a field

change visibility state of dynamic block with a field

Anonymous
Not applicable
5,070 Views
8 Replies
Message 1 of 9

change visibility state of dynamic block with a field

Anonymous
Not applicable

Hello all, 

I have posted as a reply on other post to try and find a way to make what seems to be impossible...possible...First and foremost...I KNOW THE EXACT EQUIVALENT OF SQUAT!!   about writing, reading, or understanding LISP or the verbiage associated with it. That being said, I would like to know in the most simplistic of terms, how to change the visibility state of a dynamic block using a field that is referenced from an Excel sheet. Here are the steps that I would like to take in order for what I want to accomplish to happen:

  1. open excel file
  2. input visibility state data for the block in a designated cell
  3. save the excel file
  4. open the AutoCAD dwg
  5. print (and have the block associated with the Excel input displaying the correct visibility state)

I have attached a very simple block and excel sheet with this message, in the excel sheet I have copied the block information from the various visibility states using the LIST command in AutoCAD. I am currently using AutoCAD Mechanical 2018, but this block was made in AutoCAD Mechanical 2016.

 

Here is a code that I copied from a very knowledgeable resource on LISP routines, Mr. Lee Mac, which I am sure that most of you have heard of.

 

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

 

My problem is the utterly embarrassing lack of knowledge when it comes to LISP code, so I have absolutely NO idea as to how to utilize or implement his program, what variables to change to fit my drawing or how to make it reference the field or Excel sheet. So any help would be greatly appreciated, and please, feel free to assume that you are talking to a complete idiot on the subject of LISP, because you are, and feel free to explain even OVER explain in detail the changes that I need to make in order to make this little bit of happiness work for me. Thank you in advance for all of those that have taken the time to read this, and have input to share.

 

Thank you,

 

Jetxcc

 

0 Likes
Accepted solutions (1)
5,071 Views
8 Replies
Replies (8)
Message 2 of 9

rapidcad
Collaborator
Collaborator

Hey, I can at least steer you toward how to execute Lee's program and you can start testing. I don't have time at the moment to dig into your drawing, nor do I personally use Excel to drive anything in AutoCAD, although many others do that.

 

Ok, first off, it appears that you want to run one of Lee's functions, but the way his functions are written there, he is building function upon function, in other words, some of the code in the program (function) that you posted has dependencies - those dependencies are functions that Lee uses as building blocks to stitch together in different ways in order to build different  programs out of modular code chunks called "functions".

 

You will need to go back to Lee's page and copy the rest of those dynamic block functions , then load them just like you want to do with the function you posted.

 

A few simple things to help you read what he has written:

 

Semicolons make the line of code invisible to the program, so we programmers all use them to add notes. On Lee's website they show up In green.

Everywhere you see LM:something, (without a Defun in front of it) Lee is firing a function that he wrote. Those functions must be loaded in order for AutoCAD to know their definition before you can try to run his program. I would just put them all together for you in a single lisp file but Lee's page explicitly prohibits us reposting the functions, he prefers us linking his page as I did above.You need the following functions (programs) in order to make that program work:

LM:getvisibilityparametername

LM:getdynpropallowedvalues

LM:setdynpropvalue

 

You can paste them all together in a single file yourself. Here's how:

In AutoCAD type VLIDE in the command prompt and hit enter. You will see a code editor. in the toolbar at the top of the window sue the familiar New button to start a new document. in the new document you can copy+paste in the programs from Lee's page, but make sure you get the whole program - every parenthesis - each opening one must have a closing one and the contents they enclose are executed in the order they are nested, so get the functions in their entirety and wherever semicolons are keeping notes from being read as program code, make sure the notes don't get truncated to a new line without a semicolon to mark that line as a note.

 

Once you get all four of these functions in a single window, save the file by using the familiar save button in the tool bar in the VLIDE window. For now that is all I have time to help with. at least you will enough of lee's code to actually use in a program.

 

You will still need code to go open the Excel file and get your cells, and then you will have to save the info to a variable in the lisp file like so:

(setq STRINGVARIABLE "whatever visibility name came out of that Excel cell")

 

and then you will have to have something like:

 

  (if (and
          (setq ent (car (entsel "\nSelect Dynamic Block: ")))
	  (eq "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object ent))))
          (eq :vlax-true (vla-get-isdynamicblock obj))
	  
      )
    (LM:SetVisibilityState obj STRINGVARIABLE)
    (alert " Object selected is not a valid dynamic block.")
    )

You should copy that into your file as well, just paste it at the bottom for now. I know it isn't enough to complete your request but maybe someone else can take you the rest of the way. It's a start - you  still need that Excel file data and I have no idea what you want to do to apply data from which cell to whatever block you pick - but I didn't download them either...

 

HTH, if nothing else, it keeps your thread from being pushed way down the stack...

ADN CAD Developer/Operator
Message 3 of 9

Anonymous
Not applicable

Ronald, 

Thank you for the time you took to help me with this so far. I have done as you suggested, and after I get them loaded it ask me to pick a dynamic block, and when I try, nothing happens. I'm not sure how to "run the function" again. Or if there are variables within the code that I am supposed to change or if the program "just knows" which block it's supposed to reference? the code is color coded for a reason i would assume, are the black elements the ones to change to what i need?  I almost posted the whole thing that I have pieced together but remembered your comment about NOT doing that...oops...but if you, or someone, could explain the color coding to me and what it means in relation to what I am trying to accomplish. This is what I have deciphered so far, but I am not certain.

 

PURPLE TEXT SEEMS TO BE PROGRAMMERS NOTES, NO EXPLANATION NEEDED 

RED TEXT SEEMS TO BE ONLY THE (  )'s SO NO EXPLANATION NEEDED 

BLUE TEXT SEEMS TO BE THE THE PARTS OF THE CODE THAT TELL OTHER THINGS WHAT TO DO-CLARIFICATION NEEDED

BLACK TEXT SEEMS TO BE THE NAME OF OBJECTS TO BE AFFECTED BY THE CODE-CLARIFICATION NEEDED

GREEN TEXT, NO IDEA WHAT IT IS FOR-CLARIFICATION NEEDED

MAGENTA TEXT, SEEMS TO BE MESSAGES THAT WILL BE DISPLAYED AT SOME POINT-SOME CLARIFICATION NEEDED

 

I cannot apologize enough for the frustrating nature of my ignorance on the subject, but I have hit a wall, at 120 mph with this. 

 

Thank you all for your help. 

 

 

 

 

 

 

0 Likes
Message 4 of 9

rapidcad
Collaborator
Collaborator
Accepted solution

Blue text in the VLIDE editor is any function or symbol defined within the Autolisp or ARX or other supporting language. In other words, these are the defined functions that the language comes with for you to use as operators on your own set of problems you are trying to write a program to address.

 

defun is a most commonly used one - it allows you to "define a function" of your own. We programmers like to string functions together to solve problems rather than write one great big program because we like to reuse functions to do double-duty for other programs - you do the same with dishes. You reuse dinner plates all the time instead of paper plates. We clear the function of data and maybe reuse it in a different program as a building block to accomplish a different task.

Black text in the VLIDE indicates that the word is either a variable or the name of a user defined function. They won't be both, just one or the other. I'll do something like ....

codesample.JPG  

where setq is an Autolisp language function to set a variable, pikpt is my own variable name that I came up with for pick point, getpoint is an Autolisp function that expects a point and then a prompt - the point in the example is arrwpt which is a variable that had previously been set to hold a point X,Y,Z coordinate value and the magenta text is string text that is being used as a prompt to the command line to tell the user what I want him to do.

 

When black is a function it can often be called just by enclosing it in parenthesis... (picker) which would fire my entity selection function.

 

Green text always indicates real numbers or integers to the program.

 

Magenta indicates strings of text that the programmer has supplied either to be keywords or prompts to users or as names for choices.

 

Autolisp has several data types to keep straight and they usually cannot be mixed.

Real numbers

Integers

Strings of text

lists

symbols

File descriptors

AutoCAD entity names

Selection sets

Subrs (built in functions)

 

Hope that helps with understanding the interface. there is a help button and pull down in the VLIDE editor with most of what anyone would need to know to get started.

ADN CAD Developer/Operator
Message 5 of 9

Anonymous
Not applicable

@rapidcad here is the block that i referred to in my private message to you. 

i would post the compiled code here as well, to get help from the rest of the community, but i do not want to cross any developer boundaries with Mr. Lee Mac, as it is a (VERY BUTCHERED) compilation of his codes from his website on dynamic blocks

 

For anyone else that is dying to have a mental breakdown... here is a rundown of what I'm trying to accomplish. (i just copied the comments from the code compilation that i referenced earlier) Or if you have a BETTER idea or simpler solution, I am open to suggestions. Thank you!!

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

;; thanks to Lee Mac for his code modules that i found at:

;; http://lee-mac.com/dynamicblockfunctions

;; but I need help with this code to get it to work for me, please & thank you
.
;; i would like to compile the following functions into ONE routine
;; to be able to reference different block handles and text objects. that will
;; change the visibility state of the referenced block.

;; these are the handles for the objects in the dwg that i am currently working on so i will
;; use them for reference:

;; dynamic block (handle: "10f9c")

;; text object value to reference for the "SET DYNAMIC BLOCK VISIBILITY STATE"
;; to change the visibility state of the block:

;; (handle: "113a0")

;; (the magenta text in the drawing is a text field that references the content
;; of the blue text in the drawing.

;; (handle: "1139b")

;; the text object that represents the visibility state of the block will be changed in an
;; Excel spreadsheet, so that when the AutoCAD operator opens the dwg, all fields, visibility states,
;; and other information will be updated automatically so that all that they have to do is print
;; the drawings.
;; the magenta text is the determining value for the final visibility state of the dynamic block.
;; when it changes, so does the visibility state of the dynamic block.


;; i would like the "processing part" of the code to be defined to a function that i can
;; use with another block to achieve the same results within the same dwg, and the
;; reference field object to be a variable that i can change to the reflect the visibility state
;; of a different block with it's own piece of text.

;; everything below this line to be a compiled into one function, i.e. "BkVz"

;; (see bottom of page for more notes.)

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

     CODE COMPILATION

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

;; everything above this line (or whatever is relevant) compiled into one function "BkVz"
;; that i can apply to the handle of any number of different dynamic blocks to get the
;; visibility state of a block that is referenced by its handle and set it to the value
;; of the text object referenced by ITS handle.

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;; bkTxt (this is where i would put the handle or necessary info for the text to
;; be referenced for the dynamic block i want to apply the "BkVz function to.)
;; basically the "BkVz" function would get the visibility state of a block based on its handle
;; and change it to the value of "bkTxt".

;; i may not have the proper syntax or wording for this, but this is somewhat of what i'm looking for:

;; (setq Bk1 (handent "10f9c")
;; (setq bkTxt1 (handent "113a0")

;; defun (BkVz1 (Bkvz (Bk1) : this will run all of the functions above "BkVz" for the variable set as Bk1
;; (bkTxt1 (bkTxt (handent "113a0") : this is the text reference that will change the visibility state
;; this will get and set the visibility state of the referenced block


;;; (setq Bk2 (handent "2xxx")
;; (setq bkTxt2 (handent "xxx2") : etc. etc.

;; or create a list of ALL dynamic blocks within the drawing and a list of all of the
;; text reference items that can somehow have the visibility state of the block
;; cross referenced to the corresponding value of the field text.

;; Bk1, Bk2, Bk3, etc.
;; bkTxt1, bkTxt2, bkTxt3, etc.


;; all of this would be run automatically without ANY USER INPUT OR ACTIONS necessary.

;; the text object that represents the visibility state of the block will be changed in an
;; Excel spreadsheet, so that when the AutoCAD operator opens the dwg, all fields, visibility states,
;; and other information will be updated automatically so that all that they have to do is print
;; the drawings.

;; so in laymens terms, which i am by FAR, the conversation would go like this:
;; "I have a problem." (dynblocks that need to change their visibility state)
;; "I've got a tool to fix it, althought I'm not entirely sure how to apply it" (AutoLISP function)
;; "I want to take my tool and apply it to the problem, but I would also like to be able to
;; reuse this tool over and over again applying it to several more problems, withouth having to
;; make a new tool. if my thought process, syntax, or methods are wrong, feel free to correct,
;; modify, or suggest changes at will.

;; i do not expect you to "write" the code for me, but i have very little knowledge of
;; AutoLISP so if you could put notes or comments beside the things that i need to change
;; in order to get it to work that would be greatly appreciated.

;; example : (blk) <-- change all instances of this to "???"
;; example : (viz) <-- change all instances of this to "???" etc. etc.

;; THANK YOU!!!!!!

0 Likes
Message 6 of 9

rapidcad
Collaborator
Collaborator

Jessy, I am very sorry that I could not reply to your email. I am currently buried and it appears that with my workload I will be for the foreseeable future. I wish I could have  a look at this with you but I'm having a hard time keeping up with what I am tasked with already, and I have to take a trip to help out our relatives next week as well (injured in accident).

Perhaps someone else can have a look at what you are trying to do?

Sorry about this.

Ron

ADN CAD Developer/Operator
0 Likes
Message 7 of 9

Anonymous
Not applicable

Sorry to hear that Ron, hopefully you and yours will be better soon. 

 

Don't worry about trying to work on my stuff, it sounds like you have enough on your plate as it it. As for my problem, I've got it oohh so close... just need that expert touch! lol. 

Have a good Christmas, New Year, (or appropriate glad tidings for whatever you celebrate) and maybe when you get done with all your other work and you have nothing better to do than give yourself another migraine, you can check it out.  I will post the mangled code, dwg, and Excel sheet with this so IF you get the chance and you (or anyone else is a glutton for punishment) you can mess with it, but I understand being overwhelmed this time of year so please don't feel obligated. 

 

Have a good one, and I appreciate the response!!

(defun BKVZ ( / blk idx obj sel vis )
    
    (setq blk "WELD DETAIL" ;; Block Name
          vis "EQUAL WELD"  ;; New Visibility State
    )
    (if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)))))
        (repeat (setq idx (sslength sel))
            (if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
                (LM:SetVisibilityState obj vis)
            )
        )
    )
    (princ)
)
;; need to figure out how to set the BLOCK NAME & NEW VISIBILITY STATE to some type of variable that will change as the code will step through all
;; dynamic blocks. the NEW VISIBILITY state will be referencing an attribute within the block that is referenced from an Excel worksheet.


;;THIS IS A SEPERATE CODE FOR DUMPING PROPERTIES. NOT A PART OF THE CODE ABOVE!!


;; this code dumps the properties, but it only dumps 6 of the visibility states, and some of my blocks have way more than that. is there a way
;; to make this code list ALL of the visibility state options?
(defun c:BkDP ( / )
(setq obj (vlax-ename->vla-object (car (entsel))))
(setq v (vla-getdynamicblockproperties obj))
(setq vval (vlax-variant-value v))
(setq sal (vlax-safearray->list vval))
(setq salnth (length sal))
(setq count 0)
(while (/= count salnth)
(vlax-dump-object (nth count sal))
(setq count (+ count 1))
)
(setq count nil)
(princ)
)

0 Likes
Message 8 of 9

paul.kennedyF55Y7
Community Visitor
Community Visitor

I came across this thread as I am trying to accomplish the same thing I think. I came across Lee Mac's collection of LISP functions to work with dynamic blocks (http://lee-mac.com/dynamicblockfunctions.html) but can't figure out how to string them together to get them to work properly. I am new to LISP and don't know the first thing. Can anyone point me to a page on Lee's site or elsewhere that might help clear things up? Thanks!

 

Paul

0 Likes
Message 9 of 9

Anonymous
Not applicable

Paul,

Firstly, welcome to the never-ending spiraling rabbit hole of AutoLISP! 

I guess the first question would be...What exactly are you trying to accomplish? What I have been trying to do is get an AutoLISP routine that will globally select and change the visibility states of all dynamic blocks in my dwg based on their attribute value that is referenced from an Excel spreadsheet.

 

I have been beating my head against the wall for months trying to learn AutoLISP for this one specific task... Lee Mac, Jeff Sanders , afraLISP and the various different forums augicadtutor, and AutoDesk forums have been invaluable in the learning process. Unfortunately, most of them do not realize that when some people, myself included, say "I know nothing about AutoLISP" that we mean LITERALLY NOTHING! So finding answers is sometimes frustrating because the ones that do try to help sometimes over estimate what we the unlearned understand of the AutoLISP world and refuse to write it out in crayon as I myself need sometimes. There are a few ever so gracious and patient persons out there that DO understand our limitations and with the grace and patience of a saint, try and walk us through it. So far, I have been able to piece together this code from the various aforementioned sources, and those ever so gracious saints, that will give you the handle of all the dynamic block in your dwg, and, as in my case I have all of my blocks set up with an attribute that references a cell in an Excel spreadsheet. I have also a code that will change the visibility of the block based on the block handle and visibility state, but those parameters have to be typed into the actual code, thus negating the usefulness of it. I have yet to figure out how to tie the two together so that they will work in tandem to one another... 

 

good luck! as i said these work indepentently of one another, but I have yet to get them to work together. hopefully it is something that you can use, if you get it to work for you... please post it back here so that we ALL might get a little smarter. 

 

(defun StVz (/ ss eLst bEnt aEnt aEntLst aVal blkLst) ; Define the function, localise the variables
  
  (vl-load-com) ; Load the Visual LISP console (allows vl-... commands)
  
  (if ; If there exists a selection set such that:
    (setq ss (ssget "X" ; "X" meaning search entire database for entities with:
              (list (cons 0 "INSERT") ; type: INSERT (Blocks, XRefs)
                (cons 66 1) ; Attributed
                (if    (getvar "CTAB") ; If there is a variable "CTAB" (newer releases - determines Model Space/Paper Space
                  (cons 410 (getvar "CTAB")) ; Then filter by the CTAB variable
                  (cons 67 (- 1 (getvar "TILEMODE"))) ; Otherwise use TILEMODE variable to filter.
                ) ; end if
              ) ; end list [Filter List]
           ) ; end Selection set aquirement [ssget]
      ) ; end Variable Setting [Selection set stored in variable "ss"]
    (progn ; Wrap the following code for use in the IF statement:
      (setq eLst ; Store the following list of entity names to variable "eLst"
         (vl-remove-if 'listp ; Remove from the list if the item is a List
           (mapcar 'cadr ; Produce a list of entity names (and possible coord values) from
               (ssnamex ss) ; Information provided by "ssnamex" about the Selection Set
               ) ; end Mapcar
           ) ; end vl-remove-if
        ) ; end variable setting
      (foreach e eLst ; For Each item (e) in the eLst (entity name list):
    (setq bEnt (cdr (assoc 5 (entget e))) ; Retrieve the Block Name [store to "bEnt"]
          aEnt (entnext e) ; Retrieve the Attribute Entity Name [Store to aEnt]
    ) ; end Variable setting
    (while (= "ATTRIB" (cdr (assoc 0 (setq aEntLst (entget aEnt))))) ; While the Entity Type is "ATTRIB"[ute]
      (if (= (cdr (assoc 2 aEntLst)) "AFVIZ") ; If the ATTRIBute name is "AFVIZ"
        (progn ; wrap the following for use with the IF
          (setq aVal   (cdr (assoc 1 aEntLst)) ; Store the ATTRIBute value [to aVal]
            blkLst (cons
                 (cons bEnt aVal) ; Create an Associative list (dotted pair) of Block Name and Att. Value.
                 blkLst) ; Connect this to the main list
	         ) ; End Variable Setting
        ) ; end Progn (code wrapper)
      ) ; end IF
      (setq aEnt (entnext aEnt)) ; Move onto next Attribute in Block
    ) ; End While
      ) ; End Foreach
    ) ; End Progn
    (princ "\n<!> No Attributed Blocks Found <!>") ; If No Selection Set, then No Attributed Blocks Found in Drawing.
  ) ; End IF
  (PROMPT (vl-princ-to-string blkLst)) ; Convert the Associative List to a String and Alert it in a Dialog Box to view result.
  (princ) ; Exit Cleanly - [Suppress last function return]
) ; End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(defun BkVz ()
 
    (setq blk "WELD DETAIL" ;; Block Name
          vis "EQUAL WELD"    ;; New Visibility State
    )
    (if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)))))
        (repeat (setq idx (sslength sel))
            (if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
                (LM:SetVisibilityState obj vis)
            )
        )
    )
    (princ)


;; Block Name  -  Lee Mac
;; Returns the true (effective) name of a supplied block reference
                        
(defun LM:blockname ( obj )
    (if (vlax-property-available-p obj 'effectivename)
        (defun LM:blockname ( obj ) (vla-get-effectivename obj))
        (defun LM:blockname ( obj ) (vla-get-name obj))
    )
    (LM:blockname obj)
)
(vl-load-com)

(defun c:AFVIZ ( / ss ent ed lst)
  
  (if (setq ss (ssget "X" (list (cons 0 "INSERT")
                                (cons 66 1)
                                (if (getvar "CTAB") ; If there is a variable "CTAB" (newer releases - determines Model Space/Paper Space
                                  (cons 410 (getvar "CTAB")) ; Then filter by the CTAB variable
                                  (cons 67 (- 1 (getvar "TILEMODE"))))))) ; Otherwise use TILEMODE variable to filter.
    (repeat (setq i (sslength ss))
      (setq ent (ssname ss (setq i (1- i))))
      (while (= "ATTRIB" (cdr (assoc 0 (setq ed (entget (setq ent (entnext ent)))))))
        (if (= (cdr (assoc 2 ed)) "AFVIZ") 				;; If the ATTRIBute name is "AFVIZ"
          (setq lst (cons (cons (cdr (assoc 5 (entget ent)))
                                (cdr (assoc 1 ed)))
                          lst))))))
  
  (foreach e lst
    (LM:SetVisibilityState (vlax-ename->vla-object (handent (car e))) (cdr e)))
  
  (princ)
  )
;; 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)
    )
)

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

;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; Returns: [lst] List of allowed values for property, else nil if no restrictions

(defun LM:getdynpropallowedvalues ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Name of Visibility Parameter, else nil

(defun LM:getvisibilityparametername ( blk / vis )  
    (if
        (and
            (vlax-property-available-p blk 'effectivename)
            (setq blk
                (vla-item
                    (vla-get-blocks (vla-get-document blk))
                    (vla-get-effectivename blk)
                )
            )
            (= :vlax-true (vla-get-isdynamicblock blk))
            (= :vlax-true (vla-get-hasextensiondictionary blk))
            (setq vis
                (vl-some
                   '(lambda ( pair )
                        (if
                            (and
                                (= 360 (car pair))
                                (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
                            )
                            (cdr pair)
                        )
                    )
                    (dictsearch
                        (vlax-vla-object->ename (vla-getextensiondictionary blk))
                        "ACAD_ENHANCEDBLOCK"
                    )
                )
            )
        )
        (cdr (assoc 301 (entget vis)))
    )
)

(vl-load-com) (princ)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;this is the second code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun BkVz () (setq blk "WELD DETAIL" ;; Block Name CHANGE THIS VALUE TO THE NAME OF YOUR BLOCK vis "EQUAL WELD" ;; New Visibility State CHANGE THIS VALUE TO THE VISIBILITY STATE THAT YOU WANT DISPLAYED;;
;;IF YOU CAN FIGURE OUT A WAY TO RUN THE FIRST CODE, THAT WILL GIVE YOU THE HANDLE AND THE ATTRIBUTE VALUE, AND GET IT TO ;;
;; USE THE LIST PRODUCED BY THE FIRST CODE AS THE VARIABLES IN THIS CODE... LET ME KNOW HOW YOU DID IT!! ) (if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk))))) (repeat (setq idx (sslength sel)) (if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))))) (LM:SetVisibilityState obj vis) ) ) ) (princ) ) ;; Block Name - Lee Mac ;; Returns the true (effective) name of a supplied block reference (defun LM:blockname ( obj ) (if (vlax-property-available-p obj 'effectivename) (defun LM:blockname ( obj ) (vla-get-effectivename obj)) (defun LM:blockname ( obj ) (vla-get-name obj)) ) (LM:blockname obj) ) ;; 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) ) ) ;; 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) ) ) ;; Get Dynamic Block Property Allowed Values - Lee Mac ;; Returns the allowed values for a specific Dynamic Block property. ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; Returns: [lst] List of allowed values for property, else nil if no restrictions (defun LM:getdynpropallowedvalues ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues))) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;; Get Visibility Parameter Name - Lee Mac ;; Returns the name of the Visibility Parameter of a Dynamic Block (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; Returns: [str] Name of Visibility Parameter, else nil (defun LM:getvisibilityparametername ( blk / vis ) (if (and (vlax-property-available-p blk 'effectivename) (setq blk (vla-item (vla-get-blocks (vla-get-document blk)) (vla-get-effectivename blk) ) ) (= :vlax-true (vla-get-isdynamicblock blk)) (= :vlax-true (vla-get-hasextensiondictionary blk)) (setq vis (vl-some '(lambda ( pair ) (if (and (= 360 (car pair)) (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair))))) ) (cdr pair) ) ) (dictsearch (vlax-vla-object->ename (vla-getextensiondictionary blk)) "ACAD_ENHANCEDBLOCK" ) ) ) ) (cdr (assoc 301 (entget vis))) ) ) (vl-load-com) (princ)
0 Likes