+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Super Member
    Computer Details
    woodman78's Computer Details
    Operating System:
    Win XP
    Computer:
    Dell GX280
    Discipline
    Transport
    woodman78's Discipline Details
    Occupation
    Road Design Engineer
    Discipline
    Transport
    Details
    I work in a local authority design office with a staff of 13. We carry out road schemes ranging from overlays up to 2 km long new schemes.
    Using
    Civil 3D 2011
    Join Date
    Jul 2009
    Location
    Ireland
    Posts
    694

    Default lisp to change dynamic block visibility

    Registered forum members do not see this ad.

    I am trying to change block visibility by lisp and have cobbled this together. It doesn't work though and I was wondering if someone could have a look for me. Thanks.

    Code:
     
    (defun c:Legend_Scale (/ LName BWild obj)
      (setq LName "dyn_legend") ;Get the layer's name
            (setq BWild (strcat "*" LName "*")) ;Default to LName
              (setq obj (ssget "_X" (list '(0 . "INSERT") (cons 2 BWild)))) ;And some blocks found
    (chgdynprop obj "visibility" "1:1000")
    (entupd obj)
    (princ)
    )
    (defun chgdynprop (e propname newval / obj v vval sal tot i)
    (setq obj (if (= (type e) 'vla-object) e (vlax-ename->vla-object e)))
    (if (= (vlax-get-property obj 'isdynamicblock) :vlax-true)
    (progn
    (setq v (vla-getdynamicblockproperties obj)
    vval (vlax-variant-value v)
    sal (vlax-safearray->list vval)
    tot (length sal)
    i 0
    );setq
    (while (< i tot)
    (if (= (vlax-get-property (nth i sal) "PropertyName")
    propname)
    (progn
    (vlax-put-property (nth i sal) "Value" newval)
    (setq i tot)
    );progn
    (setq i (1+ i))
    );endif
    );endwhile
    );progn
    );endif
    );chgdynprop

  2. #2
    Forum Deity BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Using
    Civil 3D 2015
    Join Date
    Nov 2009
    Posts
    4,838

    Default

    Give this a try:

    Code:
    (defun c:FOO ( / ss dynProps val)
      (vl-load-com)
      (if (setq ss (ssget "_x" '((0 . "INSERT") (2 . "*DYN_LEGEND*"))))
        (progn
          (vla-startundomark
            (cond (*activeDoc*)
                  ((setq *activeDoc*
                          (vla-get-activedocument
                            (vlax-get-acad-object))))))
          (vlax-for x (setq ss (vla-get-activeselectionset *activeDoc*))
            (if (and (= :vlax-true (vla-get-isdynamicblock x))
                     (vl-string-search
                       "DYN_LEGEND"
                       (strcase (vla-get-effectivename x)))
                     (setq dynProps (car (vlax-invoke
                                           x
                                           'getdynamicblockproperties)))
                     (vl-position
                       (cond (val) ((setq val "1:1000")))
                       (vlax-get dynProps 'allowedvalues)))
               (vlax-put-property dynProps 'value val)))
          (vla-endundomark *activeDoc*)
          (vla-delete ss))
        (prompt "\n** Nothing selected ** "))
      (princ))
    Note that if val ("1:1000") is not included in the dynamic block's AllowedValues, no action is taken.
    Last edited by BlackBox; 17th May 2011 at 01:55 pm. Reason: Code revised
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

  3. #3
    Super Member
    Computer Details
    woodman78's Computer Details
    Operating System:
    Win XP
    Computer:
    Dell GX280
    Discipline
    Transport
    woodman78's Discipline Details
    Occupation
    Road Design Engineer
    Discipline
    Transport
    Details
    I work in a local authority design office with a staff of 13. We carry out road schemes ranging from overlays up to 2 km long new schemes.
    Using
    Civil 3D 2011
    Join Date
    Jul 2009
    Location
    Ireland
    Posts
    694

    Default

    Thanks RenderMan. I keep getting "nothing selected" though. I have tried renaming blocks and different things but no joy. Any ideas?

  4. #4
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electrical.
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Great Syria , Lives in Abu Dhabi
    Posts
    4,095

    Default

    This ...

    (8 . "DYN_LEGEND")
    (2 . "DYN_LEGEND")

  5. #5
    Forum Deity BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Using
    Civil 3D 2015
    Join Date
    Nov 2009
    Posts
    4,838

    Default

    Quote Originally Posted by woodman78 View Post
    Thanks RenderMan. I keep getting "nothing selected" though. I have tried renaming blocks and different things but no joy. Any ideas?
    That means you have no blocks on the "DYN_LEGEND" layer. Perhaps I misinterpreted your original code... I took this line:

    Quote Originally Posted by woodman78 View Post
    Code:
     
    (defun c:Legend_Scale (/ LName BWild obj)
    (setq LName "dyn_legend") ;Get the layer's name
    ... To mean that would be the block's layer name? Thus, I included this:

    Quote Originally Posted by RenderMan View Post
    Code:
    (if (setq ss (ssget "_x" '((0 . "INSERT") (8 . "DYN_LEGEND"))))
    ... Where DXF code 8 is the entity's layer name. Try replacing the code in red with this:

    Code:
    (2 . "*DYN_LEGEND*")
    ... Otherwise, we'll just step through an SS of all blocks.
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

  6. #6
    Forum Deity BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Using
    Civil 3D 2015
    Join Date
    Nov 2009
    Posts
    4,838

    Default

    Quote Originally Posted by Tharwat View Post
    (2 . "*DYN_LEGEND*")
    Don't forget to add the asterisks.
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

  7. #7
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electrical.
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Great Syria , Lives in Abu Dhabi
    Posts
    4,095

    Default

    Quote Originally Posted by RenderMan View Post
    Don't forget to add the asterisks.
    Of course.

    Regards.

  8. #8
    Senior Member lamensterms's Avatar
    Computer Details
    lamensterms's Computer Details
    Operating System:
    Windows 7 - 64bit
    Discipline
    Manufacture
    lamensterms's Discipline Details
    Occupation
    Steel Detailer
    Discipline
    Manufacture
    Details
    3D Modelling - Mechanical & Structural 2D Detailing - Shop Drawings
    Using
    AutoCAD 2014
    Join Date
    May 2011
    Location
    Berwick, VIC, Australia
    Posts
    415

    Default

    Registered forum members do not see this ad.

    Hey guys,

    I’m just discovering these visibility states of dynamic blocks myself, pretty interesting and could be very useful.

    I’m just in the process of customizing a clients drawing sheet for use in our office and and just trying to understand how I can batch toggle the visibility state of a block in multiple drawings.

    The routine above looks like it should do the trick – but unfortunately when I run it – the result is “** Nothing selected **”.

    If I remove the block name filter from the selection set, the routine seems to run fine.

    My working code is…

    Code:
    (defun c:test1 ( / ss dynProps val)
      (vl-load-com)
      (if (setq ss (ssget "_x" '((0 . "INSERT"))))
        (progn
          (vla-startundomark
            (cond (*activeDoc*)
                  ((setq *activeDoc*
                          (vla-get-activedocument
                            (vlax-get-acad-object))))))
          (vlax-for x (setq ss (vla-get-activeselectionset *activeDoc*))
            (if (and (= :vlax-true (vla-get-isdynamicblock x))
                     (vl-string-search
                       "4057_STICKER"
                       (strcase (vla-get-effectivename x)))
                     (setq dynProps (car (vlax-invoke
                                           x
                                           'getdynamicblockproperties)))
                     (vl-position
                       (cond (val) ((setq val "For Client Review")))
                       (vlax-get dynProps 'allowedvalues)))
               (vlax-put-property dynProps 'value val)))
          (vla-endundomark *activeDoc*)
          (vla-delete ss))
        (prompt "\n** Nothing selected ** "))
      (princ))
    But I cannot understand why it doesn’t detect my block named "4057_STICKER". Does it have anything to do with the Anonymous Name?

    Thanks for all your help.

Similar Threads

  1. Visibility list in Dynamic Block
    By alijahed in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 10th Jun 2010, 12:58 am
  2. Script (not LISP!) to change VP visibility etc?
    By Kostritz in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 2
    Last Post: 24th May 2010, 08:17 pm
  3. change the visibility list of a dynamic block by lisp
    By alijahed in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 24th May 2010, 01:55 am
  4. Dynamic block- Visibility Parameter?
    By KnoJa31 in forum AutoCAD General
    Replies: 1
    Last Post: 10th Sep 2008, 12:15 am
  5. macro to change the visibility of a particular dynamic block
    By comcu in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 27th Jun 2007, 11:03 pm

Bookmarks

Posting Permissions

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