Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Polylines that are over a specific length

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
296 Views, 8 Replies

Change Polylines that are over a specific length

I am in need of a lsp which would change all 2d polylines in a selection
over 10ft long to a layer called "over-10ft"
I realize I can use proerties & filters but a lsp would be quicker.

Thanks!
kd
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous


Hi, here is some code that could help:

 

;;;==============================

(if (setq sset (ssget "x" '((0 .
"*POLYLINE"))))
  (foreach
   
entity
    (vl-remove-if
     
'listp
      (mapcar 'cadr (ssnamex
sset))
    )
    (setq obj
(vlax-ename->vla-object entity))
   
(if
     
(>
       
(vlax-curve-getdistatpoint
         
(vlax-ename->vla-object
entity)
         
(vlax-curve-getendpoint
           
(vlax-ename->vla-object
entity)
         
)
       
)
       
10
      )
     
(vlax-put obj 'layer "over-10ft")
    )
 
)
)

;;;==============================

 

HTH

 

--
Humans are born with a wide horizon.
As
time goes by, the horizon narrows and
narrows, until it becomes a point of
view.

 

 

I am in need of a lsp which would
change all 2d polylines in a selection
over 10ft long to a layer called
"over-10ft"
I realize I can use proerties & filters but a lsp would be
quicker.

Thanks!
kd
Message 3 of 9
Anonymous
in reply to: Anonymous


Thanks for responding

 

Using acad 2008 I get the following
error.....

 

Command: (LOAD
"C:/KD/Kd-acad/kd-Lisp/over10ft.lsp") ; error:
AutoCAD.Application: Key not
found

 

 

Any help would be
appreciated
Message 4 of 9
Anonymous
in reply to: Anonymous


The code as posted by me, works here, in AutoCAD
2008. I don't know what is in over10ft.lsp. Is there
only my code, or there is something else too ? Can you post it ?


--
Humans are born with a wide horizon.
As time goes by, the
horizon narrows and
narrows, until it becomes a point of view.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Thanks for responding

 

Using acad 2008 I get the following
error.....

 

Command: (LOAD
"C:/KD/Kd-acad/kd-Lisp/over10ft.lsp") ; error:
AutoCAD.Application: Key
not found

 

 

Any help would be
appreciated
Message 5 of 9
Anonymous
in reply to: Anonymous


(defun c:over10ft ()
(if (setq sset (ssget "x"
'((0 . "*POLYLINE"))))
  (foreach
   
entity
    (vl-remove-if
     
'listp
      (mapcar 'cadr (ssnamex
sset))
    )
    (setq obj
(vlax-ename->vla-object entity))
   
(if
     
(>
       
(vlax-curve-getdistatpoint
         
(vlax-ename->vla-object
entity)
         
(vlax-curve-getendpoint
           
(vlax-ename->vla-object
entity)
         
)
       
)
       
10
      )
     
(vlax-put obj 'layer "over-10ft")
    )
 
)
)
);;;
Message 6 of 9
Kent1Cooper
in reply to: Anonymous

Some interesting things I learned from earlier exchanges here, about lengths of objects using (vla...) functions, if 'path' is the entity name:

(vlax-curve-getDistAtPoint path (vlax-curve-getEndPoint path))

unexpectedly returns 0 for *closed* entities, but

(vlax-curve-getDistAtParam path (vlax-curve-getEndParam path))

doesn't. So if you might ever have *closed* Polylines, the end-parameter approach is better than the end-point approach. But,

(vla-get-length (vlax-ename->vla-object path))

gives the total length for Lines and Polylines [though NOT for Arcs or Circles], and would be a more code-efficient way to find lengths in this case.

Perhaps something as simple as this:

{code}
(setq plset (ssget "x" '((0 . "*POLYLINE"))))
(while (> (sslength plset) 0)
(setq plobj (ssname plset 0))
(if (> (vla-get-length (vlax-ename->vla-object plobj)) 120)
(command "_.chprop" plobj "" "_layer" "over-10ft" "")
); end if
); end while
{code}

If you might have any *3D* Polylines that you don't want changed, you'd have to account for that. If you don't, and also never have any 2D "heavy" Polylines, you can change "*POLYLINE" to "LWPOLYLINE". If you're doing Civil work and a drawing unit is a foot rather than an inch, change the 120 to 10.

--Kent Cooper


kDispoto wrote...
I am in need of a lsp which would change all 2d polylines in a selection over 10ft long to a layer called "over-10ft".
....
Kent Cooper, AIA
Message 7 of 9
Anonymous
in reply to: Anonymous


Try the next one:

 

;;;================================

(defun c:over10ft (/ sset obj)
 
(vl-load-com)
  (if (setq sset (ssget "x" '((0 .
"*POLYLINE"))))
    (foreach
     
entity
     
(vl-remove-if
       
'listp
        (mapcar 'cadr (ssnamex
sset))
      )
     
(setq obj (vlax-ename->vla-object entity))
     
(if
       
(>
         
(vlax-curve-getdistatpoint
           
obj
           
(vlax-curve-getendpoint
obj)
         
)
         
10
       
)
       
(if
         
(vla-item
           
(vla-get-layers
             
(vla-get-activedocument
               
(vlax-get-acad-object)
             
)
           
)
           
"over-10ft"
         
)
          (vlax-put obj 'layer
"over-10ft")
          (alert
"Layer 'over-10ft' not found.")
       
)
      )
    )
 
)
  (princ)
)

;;;================================

 

HTH


--
Humans are born with a wide
horizon.
As time goes by, the horizon narrows and
narrows, until it
becomes a point of view.

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


(defun c:over10ft ()
(if (setq sset (ssget "x"
'((0 . "*POLYLINE"))))
  (foreach
   
entity
    (vl-remove-if
     
'listp
      (mapcar 'cadr (ssnamex
sset))
    )
    (setq obj
(vlax-ename->vla-object entity))
   
(if
     
(>
       
(vlax-curve-getdistatpoint
         
(vlax-ename->vla-object
entity)
         
(vlax-curve-getendpoint
           
(vlax-ename->vla-object
entity)
         
)
       
)
       
10
      )
     
(vlax-put obj 'layer "over-10ft")
    )
 
)
)
);;;
Message 8 of 9
Anonymous
in reply to: Anonymous


I tried it out and it seems to work as
needed.

 

Thank you!
Message 9 of 9
Kent1Cooper
in reply to: Anonymous

You're welcome! [It's always nice to have something work the first time without testing it -- that's certainly not always the case....]
--
KC
Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost