Results 1 to 7 of 7

Thread: Changing a visibility state for a Dynamic Block

  1. #1
    Member
    Join Date
    2007-10
    Posts
    4
    Login to Give a bone
    0

    Default Changing a visibility state for a Dynamic Block

    Can somebody help me please!

    I have dynamic block inserted and I want to change the visibility list of it by lisp.

    I went through this direction:

    1. Insert the block at the user specified point, scale & rotation.
    2. Obtain the ename of the block reference using entlast.
    3. Convert it to an ActiveX object using vlax-enale->vla-object.
    4. Get the collection of dynamic block properties of that BlockRef using vla-GetDynamicBlockProperties.
    5. Using vlax-for step through the collection until you reach the property with vla-PropertyName equal to the name you gave the Visibility parameter in BEdit.
    6. Set its vla-put-Value to the relevant name.

    but I have problem in (5) and (6)!
    can somebody please help me with that?

    Cheers

    Ali

  2. #2
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Changing a visibility state for a Dynamic Block

    Congrats on your 1st post. If you look at the code I've made (see post 16) in this thread, it depends on the units type. If the units type = 0 then it's either a Flip state, Lookup, or Visibility state. Both the Vis & Lookup uses strings for their values, but the flip uses an integer.

    However, re-reading your post, you're looking for a way to modify the visibility list (unless I'm understanding wrong). That's only possible inside the block's definition. But also, it's not possible using either AutoLisp or VisualLisp (with ActiveX). As far as I can tell the only way (if you don't want to try ARX / DotNet) is to open the block in BEdit, then issue the BVState command to create extra states or delete existing states from the list.
    Last edited by RobertB; 2010-06-02 at 08:56 PM. Reason: Fixed title after thread split

  3. #3
    Member
    Join Date
    2007-10
    Posts
    4
    Login to Give a bone
    0

    Default Re: Changing a visibility state for a Dynamic Block

    Quote Originally Posted by irneb View Post
    Congrats on your 1st post. If you look at the code I've made (see post 16) in this thread, it depends on the units type. If the units type = 0 then it's either a Flip state, Lookup, or Visibility state. Both the Vis & Lookup uses strings for their values, but the flip uses an integer.

    However, re-reading your post, you're looking for a way to modify the visibility list (unless I'm understanding wrong). That's only possible inside the block's definition. But also, it's not possible using either AutoLisp or VisualLisp (with ActiveX). As far as I can tell the only way (if you don't want to try ARX / DotNet) is to open the block in BEdit, then issue the BVState command to create extra states or delete existing states from the list.
    Thanks for your reply,

    I don't want to modify it just change it.
    let's say I have visibility states 1 and 2. I insert the block and with a lisp I want to change the visibility from 1 to 2.

    Can you please, help me with this? and I have to say I just start to learn LISP programming 2 weeks ago so please explain it for a dummy person

    Cheers

    Ali
    Last edited by RobertB; 2010-06-02 at 08:55 PM. Reason: Fixed title after thread split

  4. #4
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Changing a visibility state for a Dynamic Block

    Ok, once you have the ename of the block insert (say saved in a variable en) ... convert it to an ActiveX object using vlax-ename->vla-object ... let me give an example:
    Code:
    (defun c:test (/ en eo dblist dbprop)
      (setq en (entsel)) ;Ask user to pick the block reference
      (setq eo (vlax-ename->vla-object (car en))) ;Get the ActiveX object
    
      ;;Get the DB Props collection, converting it from a variant-safearray to a list
      ;;(setq dblist (vlax-safearray->list (vlax-variant-value (vla-GetDynamicBlockProperties eo))))
    
      ;; Could use this instead
      (setq dblist (vlax-invoke eo 'GetDynamicBlockProperties))
    
      (foreach dbprop dblist ;Step through each property in the collection
        (if (= (vla-get-PropertyName dbprop) "VS-Name") ;Check if the current has the name as you gave it inside BEdit
          (if (= (vlax-get dbprop 'Value) "1") ;Check if its current state is 1
            (vlax-put dbprop 'Value "2") ;Then change it to 2
            (vlax-put dbprop 'Value "1") ;Else change it to 1
          ) ;_ end of if
        ) ;_ end of if
      ) ;_ end of foreach
    ) ;_ end of defun
    This would basically toggle between 1 & 2 each time the user picks the block. Notice that all Visibility States are strings, therefore the "1" and "2". I'm also using the undocumented vlax-get and vlax-put instead of vla-get-Value and vla-put-Value so I don't have to convert everything to variants.

    Please note this is a quick and dirty example. There's no error checking and you need to modify the property name as you'd like.
    Last edited by RobertB; 2010-06-02 at 08:55 PM. Reason: Fixed title after thread split

  5. #5
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Changing a visibility state for a Dynamic Block


  6. #6
    Member
    Join Date
    2007-10
    Posts
    4
    Login to Give a bone
    0

    Default Re: Changing a visibility state for a Dynamic Block

    Thanks mate,

    That was really helpful.
    Can you please recommend me a book in regards to learn more.
    I start with autoLISP By George O. Head which is really good to understand the basics.
    But I need to learn more about switches like ( 'Value) "1") which you used and about the concepts like entity , Active X objects, Safe Array , ...

    Cheers mate

    Ali

  7. #7
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Changing a visibility state for a Dynamic Block

    There's quite a few listed in the sticky thread in this forum called Learning Lisp, both online resources as well as some books.

Similar Threads

  1. Replies: 2
    Last Post: 2013-06-04, 02:59 AM
  2. Visibility state when inserting a Dynamic Block
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2012-06-13, 01:10 PM
  3. Replies: 2
    Last Post: 2007-08-17, 09:16 AM
  4. Changing visibility state of a Dynamic Block upon insertion
    By tim.101799 in forum Dynamic Blocks - Technical
    Replies: 9
    Last Post: 2006-10-24, 11:42 AM
  5. Lock visibility state once Dynamic Block has been inserted
    By clarkrj in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2006-05-04, 01:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •