Jump to content

Closed Loop PolyLine Total Length pls modify


Mystogan

Recommended Posts

Hi to all,

 

I've been searching all over the net, where I can get a lisp that can give total length not perimeter length.

 

I tried LeeMac and turvill, they both have same result and it is a perimeter length.

 

The scenario, I have closed polyline that form rectangle shape. This rectangle shape is look like a CABLE TRAY and definitely it is a cable tray that electrical section use to route their cable. I need to measure the total length, If I'm going to measure it one by one this will consume a lot of time for me to get the total length.And those object is more than 100 different route and size(width).

 

Hope you can help me

 

Thank you in advance

Link to comment
Share on other sites

Understand now if the cable tray is a known width and a rectangle then you can get the 4 pts of the pline look at length 2 sides subtract the width side and add the other side for a total. You could add also more rules about the width say multiples of.

 

 

so pt1 pt2 pt3 pt4 
len1 pt1-pt2 len2=pt2-pt3 
if len1=width skip else add.

Link to comment
Share on other sites

The main issue is indeed determining which side of the rectangle represents the width:

150x300 -> L=300 or L=150?

 

Another issue:

What should happen if trays with different width are selected:

150x300

150x2000

300x2000

Link to comment
Share on other sites

Roy_043 I did mention the possibility of various widths in my post and checking for that.

 

I had a further think about this and jumping in to quickly with code we are going about it the wrong way, forget a pline rectang, what should be used is either a block drawn 1x1 in size and scaled in X & Y then its easy to add all the x's, or use a dynamic block, again you can retrieve all the x values and add them up. A dynamic block allows repeat patterns in the block.

 

Going much further it makes sense pick two points, insert multiple trays as they have a maximum length and add the odd last one.

 

Ok I made a block called 200tray it is 200x1 in size inserted and used properties to change its x scale. Made a few of them.

 

Ten minutes all up including coding.

 

(defun AHtray ( / ss len tot)
(setq tot 0.0)
(setq ss (ssget (list(cons 0 "INsert"))))
(repeat (setq x (sslength ss))
(setq len (vla-get-xscalefactor(vlax-ename->vla-object(ssname ss (setq x (- x 1))))))
(setq tot (+ tot len))
)
(alert (strcat "tray length is " (rtos tot 2 2)))
(princ)
)
(ahtray)

 

Next is to add the start end point max size etc add some error checking but no dwg or rules to compare to.

 

Reminds me of next next step do a table of how many full size and all the odd ones so you have a parts list. Ah yes that other thing that I keep trying to find time to do, uses summing up block attributes.

Link to comment
Share on other sites

Hi,

 

Just an idea - if the Cable tray is a dynamic block ( which is supposed to be in my believes in this case ) then you can get the lengths of those trays via collecting the distance parameter(s) from the selected block references quite very easily and precisely otherwise can't judge on the outputs if they are just closed rectangles or with L letter shapes as I am a ware of such work.

Link to comment
Share on other sites

I agree with you Tharwat rethink the whole approach. Straights, L's, Tee's.

 

If I can find it I posted here cabletray.lsp and cabletray2.lsp which was to do with drawing cable trays to a specific style. Remember now tee with radius or chamfer.

 

I am sure a google will reveal cable tray lisp's.

 

The block to table I am working on allows you to select multiple blocks it adds up how many are the same by name and attributes so get a complete list of say a block of multiple sizes. Tharwat would this be useful for your drainage software creating quantities ?

Link to comment
Share on other sites

........ Remember now tee with radius or chamfer.

I think the measurements supposed to be taken from the center line of those trays regardless of the shape of the tray.

 

The block to table I am working on allows you to select multiple blocks it adds up how many are the same by name and attributes so get a complete list of say a block of multiple sizes. Tharwat would this be useful for your drainage software creating quantities ?

 

Thank you BIGAL, I already wrote one a long time ago which is DRBOM and can be found HERE

Link to comment
Share on other sites

I should have looked 1st.

 

Did a google and lots of stuff popped up and like your great drainage option better than reinventing the wheel.

Link to comment
Share on other sites

One solution would be to simply add the longest sides of selected polylines.

 

The code only checks if the polylines are closed and have 4 segments that are all straight.

(defun KGA_Conv_Pickset_To_EnameList (ss / i ret)
 (if ss
   (repeat (setq i (sslength ss))
     (setq ret (cons (ssname ss (setq i (1- i))) ret))
   )
 )
)

(defun CableTrayLength_MaxSide (enm / ptLst)
 (setq ptLst
   (vl-remove
     nil
     (mapcar
       '(lambda (sub) (if (= 10 (car sub)) (cdr sub)))
       (entget enm)
     )
   )
 )
 (apply
   'max
   (mapcar
     'distance
     ptLst
     (cons (last ptLst) ptLst)
   )
 )
)

(defun c:CableTrayLength ( / res ss)
 (if
   (setq ss
     (ssget
       '(
         (0 . "LWPOLYLINE") 
         (90 . 4) 
         (-4 . "&=") (70 . 1) 
         (-4 . "<NOT") (-4 . "<>") (42 . 0.0) (-4 . "NOT>")
       )
     )
   )
   (progn
     (setq res
       (apply '+ (mapcar 'CableTrayLength_MaxSide (KGA_Conv_Pickset_To_EnameList ss)))
     )
     (princ
       (strcat
         "\nTotal length of longest sides is: "
         (rtos res)
       )
     )
   )
 )
 (princ)
)

Edited by Roy_043
Added final (princ)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...