Total length from block reference

Total length from block reference

p.suderNDHYL
Participant Participant
3,410 Views
21 Replies
Message 1 of 22

Total length from block reference

p.suderNDHYL
Participant
Participant

Hi there.
First, coding is a black magic to me 😅
I'm using Lee Mac's (whose LISPs made my work way better, for what I'm forever grateful!) Length & Area Field program to display the total lenght of polylines, but I was wondering if it's possible to also get the length of polylines from within a block reference.
We have a custom program that creates block references with double meander pattern and also spits out the total lenght. We keep track of length of all other polylines via LFM and manually add the total lengh of those in block references. It would make our lives way easier to just select block references and polylines drawn by hand, run the LISP and get total length in one.
We can't explode the block references, because they contain data required for production robot.

psuderNDHYL_0-1711017812995.png

 

(In this example I need a total length of selected block and also those pink polylines)

 

I don't even know if it's doable or just a fool's errand to get the properties of objects within a block.

Thanks in advance!

0 Likes
Accepted solutions (1)
3,411 Views
21 Replies
Replies (21)
Message 2 of 22

ronjonp
Advisor
Advisor

@p.suderNDHYL Here's a quick example with not much error checking:

(defun c:foo (/ _getlength ex n s)
  (defun _getlength (o / ep)
    (if	(vl-catch-all-error-p (setq ep (vl-catch-all-apply 'vlax-curve-getendparam (list o))))
      0.0
      (vlax-curve-getdistatparam o ep)
    )
  )
  (cond	((setq s (ssget ":L" '((0 . "INSERT"))))
	 (setq n 0)
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (foreach o (setq ex (vlax-invoke (vlax-ename->vla-object e) 'explode))
	     (setq n (+ (_getlength o) n))
	   )
	 )
	 (mapcar 'vla-delete ex)
	 (alert (vl-princ-to-string n))
	)
  )
  (princ)
)
0 Likes
Message 3 of 22

pbejse
Mentor
Mentor

@p.suderNDHYL wrote:

but I was wondering if it's possible to also get the length of polylines from within a block reference.


There is a way to do that of course. Can we assume the block has unique names? or is a dynamic block? We can filter the target polyline with a specific object property ( layer, color . etc.. )

 

Would you mind posting a drawing file with a simple block?

 


@p.suderNDHYL wrote:

We can't explode the block references, because they contain data required for production robot.


Exploding the block is not an issue if you go about it the right way as demonstrated by @ronjonp  contribution.

 

0 Likes
Message 4 of 22

p.suderNDHYL
Participant
Participant

@pbejse 
Here's an example drawing with mentioned blocks.

0 Likes
Message 5 of 22

pbejse
Mentor
Mentor

Just for curiosity's sake, can you tell us what the value for "O" represents in this line?  L=34.2m - O=5.13m2 

 

0 Likes
Message 6 of 22

p.suderNDHYL
Participant
Participant

That's the effective area of the floor heating - if you'd make a 75mm offset of the shape of the block.

0 Likes
Message 7 of 22

pbejse
Mentor
Mentor

Can i assume there would be at least 2 or more instances of the target block in one drawing? 

from your example, 2 of "1-0-1b" block or is always unique? one per?

 

 

0 Likes
Message 8 of 22

p.suderNDHYL
Participant
Participant

psuderNDHYL_1-1711443518421.png


All blocks are always unique. We have multiple houses in the same drawing. We use the same layers for 1st, 2nd, 3rd (and so on) groups in each building. This is why I need it to be done by selection instead of 'sum all of specific layer'.

When we design, we usually use gibberish (like "jadsfh"), because program doesn't allow multiples, after we're done we just purge deleted blocks and use the same program to rename them to "building-floor-group". a,b,c and so on are added if there's multiple blocks for the same floor heating group.

I've attached drawing with example layout of 2 houses in one drawing.

Message 9 of 22

pbejse
Mentor
Mentor

@p.suderNDHYL wrote:

I've attached drawing with example layout of 2 houses in one drawing.


Here's a Q&D demo code [ This will only work for block entity under layer group "Groep_*"]

 

(Defun c:Demo ( / aDoc ss i lst l plineLength bname)
(setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))  
  (if (setq l 0 ss (ssget '((0 . "INSERT")(8 . "Groep_#*"))))
    (repeat (setq i (sslength ss))
      (setq ev (ssname ss (setq i (1- i))))
      (Setq bname  (getPropertyValue ev "BlockTableRecord/Name"))
      (cond
	((setq f (assoc bname lst))
	 	(setq lst (subst (list bname (+ (cadr f)(last f)) (last f))
				 f lst )))
	((vlax-for obj (vla-item (Vla-get-blocks adoc) bname)
		  (setq objType (vla-get-ObjectName obj))
		  (cond
		    ((eq objType "AcDbPolyline")	     
		       (setq l (+ l (Vlax-get obj 'Length)))
		     )
		    )
	   	l
	   )
	 (setq lst (cons (list bname l l ) lst) l 0)
	 )
	)
      )
   )
  (foreach itm lst
    (print (strcat (car itm) " : " (rtos (* 0.001 (cadr itm)) 2 4 )))
    )
  (print)
  (print (strcat "\Total Length : " (rtos (* 0.001 (apply '+  (mapcar 'cadr lst))) 2 4)))
  (princ)
  )

 

"1-1-6 : 37.2153" 
"1-1-1b : 5.7631" 
"1-1-1a : 29.4398" 
"1-1-2b : 16.4754" 
"1-1-2a : 33.0604" 
"1-1-3 : 44.5659" 
"1-1-5 : 28.0111" 
"1-1-4 : 37.3029" 
"2-1-6b : 6.8274" 
"2-1-6a : 24.3973" 
"2-1-1 : 48.0153" 
"2-1-5b : 15.2754" 
"2-1-5a : 35.6029" 
"2-1-4 : 45.5303" 
"2-1-3 : 42.1029" 
"2-1-2 : 31.4754" 

"Total Length :481.0608" 

We can of course modify this to include Polylines under layer group "Groep_*"

 

One thing i noticed on your sample drawing, some doesn't account for the "cap" , 2-1-4 as 45.3 to include the cap it would be 45.53 and 2-1-5a as 35.40 --> 35.60 with cap? is that by design? We can exclude that if that is what you're aiming for.

 

 

0 Likes
Message 10 of 22

p.suderNDHYL
Participant
Participant

First of all, thanks for helping me with this, I really appreciate it.
The program allows me to select only the blocks, not the polylines. Is there something wrong on my end?
The "cap" not being included in lenght is a design flaw in our program. The difference is small, so we just accepted to ignore it. Calculating with cap is better.

I will be a bit more specific:
I'd love to be able to select some polylines and blocks and place a text field that is a result of their length.
Maybe that's helpful, but in another program that works only for polylines, I'm using %lu2%pr0%ct8[0.001] format, so the result is in meters in my case.

It doesn't have to display the result by layer, because those can change during the design.

psuderNDHYL_0-1711449799032.png

This is how I track the group lengths during designing. I can't go over 100m, so whenever I change something I calculate the total lenght manually every time and adjust the text.

Again, thanks for taking your time and helping me with this 🙂

0 Likes
Message 11 of 22

pbejse
Mentor
Mentor

@p.suderNDHYL wrote:

The program allows me to select only the blocks, not the polylines. Is there something wrong on my end?


Nothing wrong on your end, that is exactly what the program is intended to do, maybe because of the topic is 

Total length from block reference 😄

 


@p.suderNDHYL wrote:

I'd love to be able to select some polylines and blocks and place a text field that is a result of their length.


We can do that. hang on... Does that include field values of Polylines inside blocks?

0 Likes
Message 12 of 22

komondormrex
Mentor
Mentor

komondormrex_0-1711454712849.png

 

0 Likes
Message 13 of 22

pbejse
Mentor
Mentor

@komondormrex wrote:

komondormrex_0-1711454712849.png

 


I know, i know.. you're right 😊

 

0 Likes
Message 14 of 22

p.suderNDHYL
Participant
Participant

@pbejse wrote:


We can do that. hang on... Does that include field values of Polylines inside blocks?


Um yes, I think this is what I meant 😅

0 Likes
Message 15 of 22

pbejse
Mentor
Mentor
Accepted solution

Alright, i’ll post the code. 

Walking… 

 

Refer to attached lsp file. [ LengthOfPolyAndBlocks.lsp ]

 

 

0 Likes
Message 16 of 22

marko_ribar
Advisor
Advisor

There is also this link which points to other links for floor heating :

https://www.cadtutor.net/forum/files/file/47-floor-heating/ 

 

HTH.

M.R:

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 17 of 22

p.suderNDHYL
Participant
Participant

@marko_ribar wrote:

There is also this link which points to other links for floor heating :

https://www.cadtutor.net/forum/files/file/47-floor-heating/ 

 

HTH.

M.R:


Ah yes, we are aware of this thread in our company 🙂
We use some of the stuff from there 😄

0 Likes
Message 18 of 22

pbejse
Mentor
Mentor

Have you had the chance to test attached lisp file at post #15 @p.suderNDHYL ?

0 Likes
Message 19 of 22

p.suderNDHYL
Participant
Participant

@pbejse wrote:

Have you had the chance to test attached lisp file at post #15 @p.suderNDHYL ?


I just came to work and was excited to test it. It works as intended.
Now the sad part: it looks like that when we edid the blocks with our program, instead of changing them, it creates new entities with the same name. The field text doesn't see them anymore and returns ##### after regenerating... This is something I was afraid that could happen, but was hoping it wouldn't 😕

0 Likes
Message 20 of 22

p.suderNDHYL
Participant
Participant

We'll just end up selecting everything from a group that had changed block and placing a new field, which is still better than manually adding everything on a calculator. I'm not allowed to share the program itself for inspection 😅

Thanks again for taking your time and helping me 🙂

0 Likes