Author Topic: Change DYN Block Visbility States (command line)?  (Read 2191 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Change DYN Block Visbility States (command line)?
« on: January 11, 2016, 07:40:54 AM »
Is there a method to change a blocks visibility state by the command prompt? I am messing around with swapping scales around. I want to select our company arrow and change the visibility state to what ever scale I need. Im sure I am missing something! Thanks again.
Civil3D 2020

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Change DYN Block Visbility States (command line)?
« Reply #1 on: January 11, 2016, 08:04:22 AM »
Never tried at the command line.
Can you do it with autolisp? I have a routine that sets the text on a barscale based on the scale of a viewport.










MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Change DYN Block Visbility States (command line)?
« Reply #2 on: January 11, 2016, 08:06:29 AM »
I was wanting to use the field portion of the viewport but... cant get away with that one...
Civil3D 2020

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Change DYN Block Visbility States (command line)?
« Reply #3 on: January 11, 2016, 08:43:14 AM »
Most of my North Arrows are Annotative blocks....placed in Model Space such that they automatically are rotated NORTH based on World UCS.
No need to scale or rotate them after insertion.

As paperspace North Arrows are a pain to deal with and know 100% that they are rotated correctly without some code.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Change DYN Block Visbility States (command line)?
« Reply #4 on: January 11, 2016, 01:03:14 PM »
Ok I got a chance to find something that will work. Mr. Lee does it again!

I was wondering how I can change the ("For Costing") to a ("1"=10')? I get an error

 ; error: string too long on input


Code: [Select]
(setq blk "DWA STAMP" ;; Block Name
vis "For Costing" ;; New Visibility State
)


This is his code:

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/changing-visibility-states-in-dynamic-block/td-p/5322263

Code: [Select]
(defun c:changevis ( / blk idx obj sel vis )
(setq blk "DWA STAMP" ;; Block Name
vis "For Costing" ;; New Visibility State
)
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)) '(410 . "~Model"))))
(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)
Civil3D 2020

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Change DYN Block Visbility States (command line)?
« Reply #5 on: January 11, 2016, 01:15:50 PM »
You will need to escape the double-quote in the string using the backslash escape character, i.e.:
Code: [Select]
"1\"=10'"
I'm pleased you find the code useful!

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Change DYN Block Visbility States (command line)?
« Reply #6 on: January 11, 2016, 01:17:10 PM »
DUDE IT ROCKS. It really Really ROCKS! Easy to change and kinda understand. Thank you again!
Civil3D 2020

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Change DYN Block Visbility States (command line)?
« Reply #7 on: January 11, 2016, 01:52:47 PM »
DUDE IT ROCKS. It really Really ROCKS! Easy to change and kinda understand. Thank you again!