Multiple Visibility PARAMETERS (not States!) - how to extract them via LISP?

Multiple Visibility PARAMETERS (not States!) - how to extract them via LISP?

miodrag.jovanovic.mail
Contributor Contributor
2,976 Views
15 Replies
Message 1 of 16

Multiple Visibility PARAMETERS (not States!) - how to extract them via LISP?

miodrag.jovanovic.mail
Contributor
Contributor

Hallo everyone!

Can someone direct me in the right direction at least, because I am searching for solution about 3 weeks now :D:D

The GREAT Lisp "visibility-add-eng_1_6" (which I have found via this fantastic Forum) presented interesting Idea, of having multiple Visibility Parameteres. So I would like to be able to get VP Names and Values via Lisp...

Thank any good soul that can show me at least some hint 🙂 Cheers!

 

0 Likes
Accepted solutions (1)
2,977 Views
15 Replies
Replies (15)
Message 2 of 16

pbejse
Mentor
Mentor

@miodrag.jovanovic.mail wrote:

Multiple Visibility PARAMETERS (not States!)

 


Try this : getDynBlockRecord by Gilles Chanteau 

(BLOCKVISIBILITYPARAMETER MISA 3 (Group1 - All noen))
(BLOCKVISIBILITYPARAMETER MISA 1 (2 1 3 4))
(BLOCKVISIBILITYPARAMETER MISA 2 (Group2 - All Group2 - Obj1 Group2 - Obj2 Group2 - Obj3 Group2 - Obj4 Group2 - Obj5 Group2 - Obj6 Group2 - None))
(BLOCKLINEARPARAMETER Distance)
(BLOCKLOOKUPPARAMETER Lookup)

HTH

 

 

0 Likes
Message 3 of 16

rapidcad
Collaborator
Collaborator

@miodrag.jovanovic.mail  If Gile's code doesn't fit your needs Lee Mac has some great functions to share as well...

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

 

Hope this helps.

ADN CAD Developer/Operator
0 Likes
Message 4 of 16

miodrag.jovanovic.mail
Contributor
Contributor

Thank you guys for support and help!

I am trying to make it work, and if and when I have succeded I will raport back 🙂

Stay cool!

0 Likes
Message 5 of 16

miodrag.jovanovic.mail
Contributor
Contributor

Hallo once more!

I tried to merge the Gile´s code with pbejse´s and still no luck. It seems that I need to study LISP in order to make it work, my understanding is not enough...

I tried to change this part at the beginning:

ORIGINAL CODE(pbejse-"Visibilityforyou2.0".lsp)

"(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)))"

My-bad-one:

"(setq dp
(mapcar '(lambda (d)
(list (vlax-get-tagstring d)
If (setq f (c:dumpDynParams (vlax-vla-object->ename d))) f
(Vla-get-textstring d)) d
)) (vlax-invoke e 'GetDynamicBlockProperties)"

Since I think that I need to change definition od "setq f", and to direct that function to use "c:dumpDynParams ", but ofc, code from above is wrong...

If anyone can direct me, and if it possoble at all, to learn part od LISP programming I need in order to do this change right, I would be more than thankfull!

0 Likes
Message 6 of 16

Sea-Haven
Mentor
Mentor

Not sure but maybe something like this, these are the visibilty states for the block. The multi radio buttons.lsp make the correct dcl for choice.

 

(command "-Insert"  bname pointmin  1 1  0 "" val0)
(setq blk (vlax-ename->vla-object (entlast)))
(LM:setdynpropvalue blk "Width" wid)
(LM:setdynpropvalue blk "Height" ht )
(setq visval (LM:getvisibilityparametername blk ))
(setq winlst (LM:getdynpropallowedvalues  blk visval))
(setq winlst (cons "Please Choose" winlst))
(if (not AH:Butts2)(load "Multi Radio buttons2.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans(ah:butts2 1 "v"  2  winlst))
(LM:SetVisibilityState blk ans)

 Big thanks to Lee-mac

screenshot349.png 

0 Likes
Message 7 of 16

pbejse
Mentor
Mentor

@miodrag.jovanovic.mail wrote:

Hallo once more!

....

If anyone can direct me, and if it possoble at all, to learn part od LISP programming I need in order to do this change right, I would be more than thankfull!


Are you wanting to get the visibility paramater names of a block without hardcoding the names of the lisp routine? The code "VisibilityForYou" collects the handle ,  visibilty "status" and attribute values.

 

If you do know the visibility paramater name i would suggest you embbed the names on the routine, in this case

MISA 1, 2 and 3,  [ now you're making me talk like like Jar Jar Binks 🙂 ], 

You  will then pass a list as argument to _Selection similar to this

 

(setq BlockAndVisName '(
			("SUPER-VISIBILITY-BLOCK" ("MISA 1" "MISA 2" "MISA 3"))
      			("SOMEOTHERBLOCK" ("VN 1" "VNMO"))
			)
      )

 

A list of block names and their Visibility Parameter name...

(Defun _Selection (ss bnlist / e i dp Collection)
;;;		pBe Mar 2021		;;;  
  (repeat (setq i (sslength ss))
		  	(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))
			      h (Vla-get-handle e))    			
		  	(if
			  (And
				(setq f (assoc (strcase (Vla-get-effectivename e)) bnlist))
				(setq dp
				       (mapcar '(lambda	(d)
						  (list	(vlax-get d 'PropertyName)
							(vlax-get d 'Value)
						  )
						)
					       (vlax-invoke
						 e
						 'GetDynamicBlockProperties
					       )
				       )
				)
			  )
		  	(setq Collection (cons (list h 
						     (vl-remove-if-not '(lambda (v)
									  (member (Car v) (cadr f)))
						     dp)
						     ) Collection))
			      
			 )
		    	
		      )
  	Collection	  
  )
("MISA 3" "Group1 - All") 
("MISA 1" "2") 
("MISA 2" "Group2 - All") 

 

is this the expected results?

Handle MISA 1 MISA 2 MISA 3
14E5 2 Group2 - All Group1 - All

 

HTH

 

0 Likes
Message 8 of 16

miodrag.jovanovic.mail
Contributor
Contributor
Hallo @Sea-Haven and thank You for the effort and help!
I will certainly research in this direction also and learn, but this would be not the solution for my situation...
Thx!
0 Likes
Message 9 of 16

miodrag.jovanovic.mail
Contributor
Contributor
Hallo @pbejse and thx You for help and patience! Misa mui mui grateful 😄
Yes, the expected result would be pretty similar to that:
Handle/Visibility1//Lookup1/Lookup2.../Visibility2/Lookup1/Lookup2..../ ATT1/ATT2/...
I wanted o modify Your fantastic Lisp to get Visibility Parameters, States(lookups) and Attributes in .csv
Please do accept my apology for bothering You 🙂
I will try to implement Your code and see what happens 🙂
Stay cool!

0 Likes
Message 10 of 16

miodrag.jovanovic.mail
Contributor
Contributor

Unfortunately, after trying to solve it myself, I can not get past the error:
"; error: bad argument type: listp "SUPER-VISIBILITY-BLOCK" "

 

 

(setq BlockAndVisName '(
("SUPER-VISIBILITY-BLOCK" ("MISA 1" "MISA 2" "MISA 3"))

)
)
(Defun _Selection (ss bnlist / e i dp Collection)
;;; pBe Mar 2021 ;;;
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))
h (Vla-get-handle e))
(if
(And
(setq f (assoc (strcase (Vla-get-effectivename e)) bnlist))
(setq dp
(mapcar '(lambda (d)
(list (vlax-get d 'PropertyName)
(vlax-get d 'Value)
d             ; I have found this letter to be absent from "original" code, so I tried with or without it, but same result, same error...
)
)
(vlax-invoke
e
'GetDynamicBlockProperties
)
)
)
)
(setq Collection (cons (list h
(vl-remove-if-not '(lambda (v)
(member (Car v) (cadr f)))
dp)
) 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 '("AAA" ; "VISIBILITY_STATUS"
)
)
;;; pBe Feb 2020 ;;;
(if
(and
(= (getvar 'Dwgtitled) 1)
(setq ppc (ssget '((0 . "INSERT")(66 . 1)(2 . "`*U*,SUPER-VISIBILITY-BLOCK"))))
(setq VisColl (_Selection ppc "SUPER-VISIBILITY-BLOCK"))
(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*,SUPER-VISIBILITY-BLOCK"))))
(setq VisColl (_Selection ppc "SUPER-VISIBILITY-BLOCK"))
(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 11 of 16

Sea-Haven
Mentor
Mentor

I think what you need is get propertyname then get the value of that property name. 

 

Look at this by Lee-Mac

;; Get Dynamic Block Property Value  -  Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)

(defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)
0 Likes
Message 12 of 16

pbejse
Mentor
Mentor

@miodrag.jovanovic.mail wrote:
Handle/Visibility1//Lookup1/Lookup2.../Visibility2/Lookup1/Lookup2..../ ATT1/ATT2/...
I wanted o modify Your fantastic Lisp to get Visibility Parameters, States(lookups) and Attributes in .csv

Didn't realize you also wanted attribute values, the drawing sample you posted doesnt have attributes. That is why its very important to give a complete description and a sample that shows the actual conditions.

 

I understand that there are more than one visibility or lookup on a block and attributes.  That is want i want to see , an actual csv file based on an actual drawing with all the components that you want to show. AND how it actually look on the csv file. So we can resolve this in one go.

 

 

0 Likes
Message 13 of 16

miodrag.jovanovic.mail
Contributor
Contributor

@pbejse ,please do accept my sincery apologize!

As usually, when I want not to bother with details, and be short and precise, I choose wrong moment to do it. Allow me to try to correct it 🙂

You have made superb Lisp, that extracts Visibility(one parameter, as we usually have)-its Visibility State+Attributes in .csv(VOTF), and then we can update and return values back(VIFF) into Cad. Then I have found another lisp(visibility-add-eng_1_6)-to create more than one Visibility Parameter, but then I could not use Your lisp(easy way to update Vis. State+ATT via excel). What I was actually trying to ask -is there a wayto modify VOTF lisp, to take all Parameters, not just one?

Attached are A) .csv which I am hoping to have...Hande/Vis.Parameter1/Vis.Par2.../ATT1/ATT2... B) .dwg I have corrected (http://poleshchuk.spb.ru//cad/2009/tainypod12e.htm)

Thx for patience, really... noob here...

0 Likes
Message 14 of 16

pbejse
Mentor
Mentor
Accepted solution


@miodrag.jovanovic.mail wrote:

@pbejse ,please do accept my sincery apologize!

.....

What I was actually trying to ask -is there a wayto modify VOTF lisp, to take all Parameters, not just one?

No bother at all.  You just need to be clear on your requirements.

 

This generic code will export/import values that includes ONLY  Hande | Visibility | Lookup | Attributes ,

One thing you need to watch out for when writing to csv files, attributes and Visibility name with "," will have a undesired effect on the exported results.

 

Also this version is not limited to one specific block

Handle Visibility Visibility2 Lookup TAG1 TAG2 Visibilty1 Lookup1 TAG_1 TAG_2
FFD7 Some More 1 ABC XYZ        
FFA7 Other Less 3 DEF UTV        
FF1E           Banana Top one five
FEEE           Banana Bottom two five
E724 Horse             BARN  
E6F4 Donkey             BACKYARD  

 

You'll know it when you see it. the rest of us here undertand what I'm trying to say.

 

Exporting to CSV

command: VOTF  ( Values  Out To File )

 

Improting Data

command: VIFF (Values Import From File )

 

Modified functions:

_Selection <-- to include mulitple Visibility and Lookup values | No argument for bock names

VOTF <-- not Tag | Block names | Parameter names dependent 

VIFF <-- Modified to write values for mulitple Vis and Lookup paramaters

 

Additional codes

;; Get Visibility Parameter Name - Lee Mac 

LM:getvisibilityparameternames <-- modified for multiple Visibilty and Lookup parameter names

 

HTH

 

0 Likes
Message 15 of 16

miodrag.jovanovic.mail
Contributor
Contributor

@pbejse , this is absolutely fantastic! WOW!

I can not thank You enough! 

Sorry for bothering and making it harder, then necesery 🙂

Stay cool and the Force is with You! 🙂

0 Likes
Message 16 of 16

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.

Thanks

Buddy 

 

0 Likes