Lisp for sum of a block property

Lisp for sum of a block property

jkeys7S5HVH
Explorer Explorer
642 Views
9 Replies
Message 1 of 10

Lisp for sum of a block property

jkeys7S5HVH
Explorer
Explorer

I have a block that has a length component I want to use a lisp for since I use many of them in my drawings. I imagine it would be similar to TLEN. I have found many posts about interacting with block properties and attributes but havent been able to find this specific issue.

 

Thanks for you help in advance.

0 Likes
Accepted solutions (1)
643 Views
9 Replies
Replies (9)
Message 2 of 10

pbejse
Mentor
Mentor

@jkeys7S5HVH wrote:

I have a block that has a length component...


Is that a Dynamic block parameter? 

 

0 Likes
Message 3 of 10

Sea-Haven
Mentor
Mentor

Post a sample dwg. Getting a attribute value and summing them is not hard but need your block to get an idea of how to approach.

0 Likes
Message 4 of 10

rl_jackson
Mentor
Mentor

I have a block that has attributes for parking spaces, one attribute for regular space and one for handicap spaces. when I complete the drawing, I select the blocks using DATA EXTRACTION, and create a CSV file with HC and Regular spaces that can be added up with the SUM command in Excel. Is that what your looking for?


Rick Jackson
Survey CAD Technician VI

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 5 of 10

Sea-Haven
Mentor
Mentor

If you have CIV3D there is a sample carpark dwg imperial and metric that has numerous car park dynamic blocks.

Parking Tools - Metric.dwg well worth having a look at.

0 Likes
Message 6 of 10

jkeys7S5HVH
Explorer
Explorer

@Sea-HavenHere is the block I use. I would like to have it function like TLEN where I have a window in c3d rather than data_extraction that utilizes excel. I thought it would be easier to reroute TLEN to reference a block but thats not been fruitful for me.

 

Thanks for the help.

0 Likes
Message 7 of 10

pbejse
Mentor
Mentor
Accepted solution

 

(Defun c:TlenD (/ ss i total e)
  (if
    (setq Total	0
	  ss	(ssget "_X"
		       '((0 . "INSERT")
			 (2 . "DYN_WATER_METER2,`*U*")
			 (8 . "IRRIGATION-METER")
			)
		)
    )
     (repeat (setq i (sslength ss))
       (Setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
	(And
	  (eq (strcase (Vla-get-EffectiveName e)) "DYN_WATER_METER2")
	       (vl-some
		 '(lambda (d)
		    (if	(Eq (strcase (vla-get-PropertyName d)) "DISTANCE1")
		      (setq total (+ total (Vlax-get d 'Value)))
		    )
		  )
		 (vlax-invoke e
		   'GetDynamicBlockProperties
		 )
	       )
	     )
	  )
    )
  (princ (strcat "\nTotal Distance: " (rtos total 2 2)))
  (princ)
)

 

HTH

0 Likes
Message 8 of 10

jkeys7S5HVH
Explorer
Explorer

@pbejseThat works really well! Can I tweak it to only sum my selection? I often have various sets of those blocks that I need to sum, but separately.

Thank you!

0 Likes
Message 9 of 10

pbejse
Mentor
Mentor

@jkeys7S5HVH wrote:

@pbejseThat works really well! Can I tweak it to only sum my selection? I often have various sets of those blocks that I need to sum, but separately.

Thank you!


Sure.

Replace this [ Remove "_X" ]

(setq Total	0
	  ss	(ssget "_X"
		       '((0 . "INSERT")
			 (2 . "DYN_WATER_METER2,`*U*")
			 (8 . "IRRIGATION-METER")
			)
		)
    )

With this [ without the "_X" ] 

(setq Total	0
	  ss	(ssget 
		       '((0 . "INSERT")
			 (2 . "DYN_WATER_METER2,`*U*")
			 (8 . "IRRIGATION-METER")
			)
		)
    )

Then you're good to go.

 

 

 

0 Likes
Message 10 of 10

jkeys7S5HVH
Explorer
Explorer

@pbejseThats great, thank you for your help!

0 Likes