Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 11 of 20 (360 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-28-2013 11:23 PM in reply to: mid-awe

mid-awe wrote:

That does seem simple, but it could take several days to change all of the dynamic blocks to that format. To be honest I'm  strapped for time now and if it's possible to get the value of the invisible/contstant attribute for each Visibility state it would help out a lot. Also, I only need the value from the active visibility state. 

 

I will use this in conjunction with my block counting code so that as the blocks are counted the values of the visibility state along with the botanical names can be stored into the dictionary to build the legend.

 

I'm back at my desk this morning so I'm attaching the correct version of the block I attached earlier. (just in the case that it may help.)

 

Thank you again this is a big help. :smileyhappy:


This test code is for Palms_DYN block, we can easily modify this to work on you other dblocks

 

(Defun c:PalmVal (/	    BlockColl _InviVal	_DP	  count
		  ss	    i	      e		blkn	  ivs
		  val	    data      datalist	CurrentVis&Vlaue
		 )
;;;		pBe		;;;
  (vl-load-com)
  (setq	BlockColl (Vla-get-blocks
		    (vla-get-ActiveDocument (vlax-get-acad-object))
		  )
  )
  (defun _InviVal (bl bn / val)
    (vlax-for itm (vla-item bl bn)
      (if (eq (vla-get-objectname itm) "AcDbAttributeDefinition")
	(setq val (cons (vla-get-textstring itm) val))
      )
    )
    (reverse val)
  )
  (defun _DP (en) (vlax-invoke en 'GetDynamicBlockProperties))
  (defun count (lst / i cnt nlst)
    (while (setq i (car lst))
      (setq lst	(cdr lst)
	    cnt	(length lst)
      )
      (setq lst	 (vl-remove i lst)
	    nlst (cons (list i (1+ (- cnt (length lst)))) nlst)
      )
    )
    nlst
  )
  (if (setq ss (ssget "_X"
		      (list '(0 . "INSERT")
			    '(2 . "`*U*,Palms_DYN")
			    (cons 410 (getvar 'ctab))
		      )
	       )
      )
    (progn (repeat (setq i (sslength ss))
	     (setq e	(vlax-ename->vla-object (ssname ss (Setq i (1- i))))
		   blkn	(vla-get-effectivename e)
	     )
	     (if (eq blkn "Palms_DYN")
	       (progn
		 (if (not (assoc blkn DataList))
		   (setq vis	  (vlax-get (car (_DP e)) 'AllowedValues)
			 val	  (_InviVal BlockColl blkn)
			 DataList (cons	(list blkn
					      (mapcar '(lambda (x y)
							 (cons x y)
						       )
						      vis
						      val
					      )
					)
					DataList
				  )
		   )
		 )
		 (setq data (cons
			      (assoc (vlax-get (car (_DP e)) 'Value)
				     (cadr (assoc blkn DataList))
			      )
			      data
			    )
		 )
	       )
	     )
	   )
	   (foreach itm	(count data)
	     (print itm)
	   )
    )
  )
  (princ)
)

 

command: Palmval

 

(("Pindo" . "Butia capitata") 1)
(("Pygmy" . "Phoenix robelinii") 2)
(("Queen" . "Syagrus romanzoffiana") 2)
(("Mexican Fan" . "Washintonia robusta") 1)
(("Mediterranean Fan" . "Chamaerops humilis") 1)
(("Bismark" . "Bismarckia nobilis") 4)
(("Sabal" . "Sabal Palmetto") 1)
(("Windmill" . "trachycarpus fortunei") 2)
(("Date" . "Phoenix dactylifera") 1)

 

HTH

 

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 12 of 20 (354 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-28-2013 11:43 PM in reply to: pbejse

Here's a thought, why not use an editable attribute, <Not Invisible nor constant> for the first (or last)  visibility of the DB

That way you can add more data for any block

 

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 13 of 20 (347 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-29-2013 10:14 AM in reply to: pbejse

WOW! :smileysurprised:

 

That is crazy AWESOME! That gives the count + dotted pairs of common name with botanical names!  Exactly what I had thought about but had no idea how to pull it off.  You are A LISP magician!

 

Now, how to modify this to work on the other dblocks?

 

Thank you. You are amazing! :smileyhappy:

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 14 of 20 (346 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-29-2013 10:18 AM in reply to: pbejse

pbejse wrote:

Here's a thought, why not use an editable attribute, <Not Invisible nor constant> for the first (or last)  visibility of the DB

That way you can add more data for any block

 


That is an intriguing idea. I was conscidering hard coding some information like order numbers and such. Obviously I didn't think in this direction because filtering the additional content is well beyond my current skills. I still struggle with lambda, macar, and reactors.:smileyindifferent:

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 15 of 20 (333 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-29-2013 08:58 PM in reply to: mid-awe

mid-awe wrote:

.....I was conscidering hard coding some information like order numbers and such....


That would've been my next suggestion, tracking which "invisible" attribute goes with the visiblity is quite cumbersome.Fortunately for your sample block each visibilty has a corresponding invisible attribute and there's only one Dynamic parameter to process.

 

IMO sans adding more info on your block (editable attributes), hard coding is the way to go. Not having acces on the rest of your DBs , I cannot guarantee the result

 

<<< Now, how to modify this to work on the other dblocks?>>

 

Change this

(setq ss (ssget "_X"  (list '(0 . "INSERT")
       '(2 . "`*U*,Palms_DYN")
       (cons 410 (getvar 'ctab)))))

to

(setq ss (ssget "_X"  (list '(0 . "INSERT")
       '(2 . "`*U*,Palms_DYN,BLOCK1,BLOCK2,BLOCK3")
       (cons 410 (getvar 'ctab)))))

 

and this

(eq blkn "Palms_DYN")

to

(member (strcase blkn)  '("PALMS_DYN" "BLOCK1" "BLOCK2" "BLOCK3"))

 

"BLOCK1......" <--- whatever the other DBs block names

 

Holler if you need more help.

 

Cheers

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 16 of 20 (324 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-30-2013 05:01 AM in reply to: pbejse

Thank you. :smileyvery-happy:

 

BTW- I do have one of the dblocks that has a rotate action added. I will have to try it out to see if it works.

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 17 of 20 (315 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-30-2013 06:56 AM in reply to: pbejse

I just made the changes and a test run. :smileyvery-happy: It's working perfectly, even on the dblock with the rotate action. Thank you again, you have been a tremendous help!

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 18 of 20 (311 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-30-2013 07:20 AM in reply to: pbejse

One last question, I promise :smileyindifferent:

 

How hard would it be to get the block name also? So that the the output is like:

 

((("Sago" . "Cycas revoluta") 1) "Palms_DYN")

 

or anything that contains that dblock name.

 

 

I have built a function that simply returns my plants list,

 

(PLANTNAMES) -returns *allPLANTS* global

 

 I use it like this:


(setq PALM (nth 0 *allPLANTS*) TREE (nth 1 *allPLANTS*) SHRUB (nth 2 *allPLANTS*) GROUNDCOVER (nth 3 *allPLANTS*) VINE (nth 4 *allPLANTS*) ACCENT (nth 5 *allPLANTS*) CACTUS (nth 6 *allPLANTS*))

 

In another function I should be able to hard code any additional information, but it would be nice to have the block name right there for reference while assembling the page legend. I could lop off the "_DYN" from the dblock name to get the category easier and then (strcat (loppedDBLOCKname "_callout")) or something.

 

Thank you again.

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 19 of 20 (305 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

01-30-2013 08:34 AM in reply to: mid-awe

I think that I've got it. Thank you again for all of your help.

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 20 of 20 (259 Views)

Re: Invisible Attribute Constant Dynamic Block Visibility State?

03-03-2013 07:48 PM in reply to: pbejse

I have had to LISP all of the botanical names because the routine above got confused somehow and fell out of order. My lisp when called just added ALL of the plants and botanical names to the dictionary so that I could call them later, but it's still not as manageable as my original idea of using the block visibility state to do it. So rather than LISP-ing some more I discovered a better idea. In the dynamic block I will add a block lookup that is tied to the visibility state. As long as it will work with invisible attributes it should be suitable for my needs and be easy to manage in the future. I'll need to do the block count on visibility states like before so ican get quantity, plant name, blockname, and botanicalname.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community