Update dynamic block visibility state via excel input

Update dynamic block visibility state via excel input

fkp7057
Advocate Advocate
5,223 Views
30 Replies
Message 1 of 31

Update dynamic block visibility state via excel input

fkp7057
Advocate
Advocate

Hi all,

 

here i need your little help.. to complete my work..
in my drawing i have 100+ block that block have same name, only i have to change its visibility state.
i have excel file as input for that visibility state now i want to update that block visibility using excel/lisp/script file or other easy way.. bcoz i am using lookup table to achieve the visibility

 

Regards,

FKP

0 Likes
Accepted solutions (2)
5,224 Views
30 Replies
Replies (30)
Message 21 of 31

smrifas
Contributor
Contributor

Dears,

 

It's simple dynamic block I created

but this VOTF comment is not working here.

Please give me the solution and its required attribute the how I add that i tried lot

 

I wanted to apply this multiple drawing.

Ex:- Drawing 1 - IDF Type 1 , Drawing 2 - IDF Type 4 like that

and same like multiple dynamic blocks I wanted to set  to each drawing

 

Please give me the solution

The drawing has attached here

 

 

0 Likes
Message 22 of 31

fkp7057
Advocate
Advocate

This lisp routine made for my block ony... If you want creat for your own block then you have to modified it.. like block name, attributes etc

0 Likes
Message 23 of 31

smrifas
Contributor
Contributor

I am beginner.

I need here only works VOTF, VIFF.

why this is not working here.

I wanted to control by excel only visibility of the particular dynamic block

Can you please check the drawings what's wrong? 

 

0 Likes
Message 24 of 31

fkp7057
Advocate
Advocate

@smrifas  you please ask to @pbejse  for modification he has created this lisp routine..

the code which is @pbejse given is only applicable for my block.

0 Likes
Message 25 of 31

fkp7057
Advocate
Advocate

Final Files.

0 Likes
Message 26 of 31

miodrag.jovanovic.mail
Contributor
Contributor

Hallo!

 
 
 would it be too much to ask for a minor change of lisp-code - I just found out about lisp(visibility-add-eng_1_6) that can make multiple Visibility Parameters, but Your fantastic Lisp can extract only one VP...
If its not too much of work, would You be so kind to make it possible to extract more VP from Dynamic Block?
 
 Sorry for bothering, I tried to correct code, but witout success...
THX!

 

0 Likes
Message 27 of 31

pbejse
Mentor
Mentor

@miodrag.jovanovic.mail wrote:
... but Your fantastic Lisp can extract only one VP...
If its not too much of work, would You be so kind to make it possible to extract more VP from Dynamic Block?
 
 Sorry for bothering, I tried to correct code, but witout success...
THX!

 


Not sure what that means @miodrag.jovanovic.mail , if you dont mind posting a drawing sample, and any other information that shows your intended results. Its better for me to understand your requirements.

 

Where is your code? that would give me an insight on what you're trying to achieve.

 

 

 

0 Likes
Message 28 of 31

miodrag.jovanovic.mail
Contributor
Contributor

Hallo @pbejse !

Thaank You for answering in such a short notice and sorry for my blunt question!
I am trying to use Your Lisp ("Visibilityforyou2.0.LSP") for Dynamic Block with couple of Visibility Parameters(I do not mean States) - that Dynamic Block was made with another Lisp("visibility-add-eng_1_6"). You will find both in attachment. 

Unfortenatly "Visibilityforyou2.0.LSP"  extracts just one Visibility Parameter, and here I have more. That is my problem 🙂

I have just one Attribute ( Tag is "A"), Block Name is "B11"... I understand part of Lisp, but I lack "code-words" in order to modify it

 

 

(Defun _Selection (ss bn / e i dp Collection)
;;; pBe Feb 2020 ;;;
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))
h (Vla-get-handle e))
(if
(And
(eq (strcase (Vla-get-effectivename e)) bn)
(setq atv (mapcar '(lambda (at)
(list (Vla-get-tagstring at)
(if (setq fld (gc:FieldCode (vlax-vla-object->ename at))) fld
(Vla-get-textstring at)) at
)) (vlax-invoke e 'GetAttributes)))
(setq dp
(mapcar '(lambda (d)
(list (vlax-get d 'PropertyName)
(vlax-get d 'Value)
d
)
)
(vlax-invoke
e
'GetDynamicBlockProperties
)
)
)
(setq f (Cdr (Assoc "Visibility1" dp)))
)
(setq Collection (cons (list h f
(vl-remove-if-not '(lambda (v)
(member (Car v) taglist))
atv)) Collection))

)

)
Collection

)

(defun _FileOpen-p ( filename / f )
(if (setq f (open filename "a"))
(close f)
t
)
)

(defun _concatenate (lst m)
(setq f (if m '(cadr st) 'st))
(apply 'strcat (mapcar '(lambda (st)
(strcat "," (eval f))) lst ))
)

(defun c:VOTF ( / ppc opf externalFile a e dp VisColl) ;; Visibility Out To File

(setq taglist '("A"
)
)
;;; pBe Feb 2020 ;;;
(if
(and
(= (getvar 'Dwgtitled) 1)
(setq ppc (ssget '((0 . "INSERT")(66 . 1)(2 . "`*U*,B11"))))
(setq VisColl (_Selection ppc "B11"))
(setq externalFile (strcat (getvar 'dwgprefix)
(strcat (vl-filename-base (getvar 'dwgname)) ".csv"))
)
(setq csvStatus (not (_FileOpen-p externalFile)))
)
(progn

(setq opf (open externalFile "w"))
(write-line (strcat "Handle,Visibility" (_concatenate taglist nil))
opf)
(While (setq a (Car VisColl))
(Write-line (strcat (car a)","(caadr a)
( _concatenate (caddr a) t)
)
opf)
(setq VisColl (Cdr VisColl))
)
(close opf)
(if
(vl-catch-all-error-p
(vl-catch-all-apply 'LM:open (list externalFile))
)
(alert (strcat "Please close file\n" externalFile)))

(princ (strcat "\nFile name amd Location: " externalFile))
)
(princ (Strcat "\n<<<<<<<<<< "
(cond
( (null ppc) "No Valid selection" )
( (null VisColl) "No attributese found" )
( (null externalFile) "No CSV filename specified" )
( (null csvStatus) (strcat externalFile
"Opened for editing" )
)
)
" >>>>>>>>>>")
)
)
(princ)
)


(defun c:VIFF ( / ppc externalFile opf a data_lst d e f p VisColl) ;; Visibility In From File
;;; pBe Feb 2020 ;;;
(defun _DelTolst (str m / pos x lst lst2)
(if (setq pos (vl-string-position m str))
(cons (substr str 1 pos)
(_DelTolst (substr str (+ pos 2)) m)
)
(list str)
)
)
(if
(and
(= (getvar 'Dwgtitled) 1)
(setq ppc (ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "`*U*,B11"))))
(setq VisColl (_Selection ppc "B11"))
(setq externalFile (strcat (getvar 'dwgprefix)(Vl-filename-base (getvar 'dwgname)) ".csv"))
(or
(findfile externalFile)
(setq externalFile (getfiled "Select Visibility Data" (getvar 'dwgprefix) "csv" 16))
)
)
(progn
(textscr)
(setq opf (open externalFile "r"))
(while (setq a (read-line opf))

(if (and
(setq p (vl-string-position 44 a))
(setq data_lst (_DelTolst a 44))
(setq f (assoc (Car data_lst) VisColl))
)
(progn
(vlax-put (cadadr f) 'Value (Cadr data_lst))
(foreach itm
(mapcar 'list taglist (cddr data_lst))
(if (setq d (assoc (car itm) (caddr f)))
(Vla-put-textstring (caddr d) (cadr itm))
)
)

(princ (strcat "\nHandle \"" (Car data_lst) "\" Visibiltiy \"" (Cadr data_lst) "\" is set and specific Attributes restored"))
)
)
)
(close opf)
)
)
(princ)
)


;;; Helper functions by others ;;;
;;; ;;;


;; Open - Lee Mac
;; A wrapper for the 'Open' method of the Shell Object
;; target - [int/str] File, folder or ShellSpecialFolderConstants enum

(defun LM:open ( target / rtn shl )
(if (and (or (= 'int (type target)) (setq target (findfile target)))
(setq shl (vla-getinterfaceobject (vlax-get-acad-object) "shell.application"))
)
(progn
(setq rtn (vl-catch-all-apply 'vlax-invoke (list shl 'open target)))
(vlax-release-object shl)
(if (vl-catch-all-error-p rtn)
(prompt (vl-catch-all-error-message rtn))
t
)
)
)
)

;; gc:FieldCode (gile)
;; Returns the string value of a text mtext or attribute with field code
;;
;; Argument : the entity name (ENAME)

(defun gc:FieldCode (ent / foo elst xdict dict field str)

;;--------------------------------------------------------;;
(defun foo (field str / pos fldID objID)
(setq pos 0)
(if (setq pos (vl-string-search "\\_FldIdx " str pos))
(while (setq pos (vl-string-search "\\_FldIdx " str pos))
(setq fldId (entget (cdr (assoc 360 field)))
field (vl-remove (assoc 360 field) field)
str (strcat
(substr str 1 pos)
(if (setq objID (cdr (assoc 331 fldId)))
(vl-string-subst
(strcat "ObjId " (itoa (gc:EnameToObjectId objID)))
"ObjIdx"
(cdr (assoc 2 fldId))
)
(foo fldId (cdr (assoc 2 fldId)))
)
(substr str (1+ (vl-string-search ">%" str pos)))
)
)
)
str
)
)
;;--------------------------------------------------------;;

(setq elst (entget ent))
(if (and
(member (cdr (assoc 0 elst)) '("ATTRIB" "MTEXT" "TEXT"))
(setq xdict (cdr (assoc 360 elst)))
(setq dict (dictsearch xdict "ACAD_FIELD"))
(setq field (dictsearch (cdr (assoc -1 dict)) "TEXT"))
)
(setq str (foo field (cdr (assoc 2 field))))
)
)

;; gc:EnameToObjectId (gile)
;; Returns the ObjectId from an ename
;;
;; Argument : an ename

(defun gc:EnameToObjectId (ename)
((lambda (str)
(hex2dec
(substr (vl-string-right-trim ">" str) (+ 3 (vl-string-search ":" str)))
)
)
(vl-princ-to-string ename)
)
)

;;============================================================;;

;; hex2dec (gile)
;; Converts an hexadecimal (string) to a decimal (int)
;;
;; Argument : a string figuring an hexadecimal

(defun hex2dec (s / r l n)
(setq r 0 l (vl-string->list (strcase s)))
(while (setq n (car l))
(setq l (cdr l)
r (+ (* r 16) (- n (if (<= n 57) 48 55)))
)
)
)


(prompt

(strcat
"\n::---------------------------------------------------------::"
"\n:: VOTF to Write to file | VIFF for READ from file ::"
"\n::---------------------------------------------------------::"
)
)

(princ)

 

 

 

0 Likes
Message 29 of 31

pbejse
Mentor
Mentor

And where is the sample drawing file to test the code?

 

0 Likes
Message 30 of 31

miodrag.jovanovic.mail
Contributor
Contributor

Sorry, I thought I put it in attachment...

 

0 Likes
Message 31 of 31

Nawaid
Enthusiast
Enthusiast

Dear

I am using your lisp Visibilityforyou2.0.LSP. This is very help full me. I need x and y location of dynamic block in this same lisp.

Like:

HandleVisibilityNODE_NO.STRESS_DISCP.X LOCATION X LOCATION 
81B61REST+GUIDENN-640R+Gxxxxxxxx

I am lisp specialist, like you people, but I have ideas which i can share. Please help me.

Thanks

Buddy 

0 Likes