Replace Polyine Geometry With Another Polylines Geometry - Lisp?

Replace Polyine Geometry With Another Polylines Geometry - Lisp?

ceethreedee.com
Collaborator Collaborator
5,312 Views
40 Replies
Message 1 of 41

Replace Polyine Geometry With Another Polylines Geometry - Lisp?

ceethreedee.com
Collaborator
Collaborator

I am using Civil 3D and quite often we use polylines as targets/boundaries etc. Can be quite annoying if you want to change them. 

 

I am curious if it would be possible via lisp to maintain the same object handle of a polyline and but replace all of its geometry with another selected polyline. Anyone got anything they have currently written that might do that?

Civil 3D 2025 / Infraworks 2025
Win 10 -DELL Precision Notebook 7680

Want FREE TOOLS! Come get my free productivity tools for civil 3d from the appstore here Ceethreedee tools
Or from my website below!
https://ceethreedee.com/ceethreedee-tools
Accepted solutions (1)
5,313 Views
40 Replies
Replies (40)
Message 21 of 41

john.uhden
Mentor
Mentor
There is no command. They are just functions you can employ in your own
code as you see fit. F'rinstance they are written to handle only
LWpolylines, so you will have to vet a selected entity to be sure it
qualifies. Dealing with heavies would require lengthier code.
But you could use the AutoCAD command CONVERTPOLY to convert heavies into
lights first.

John F. Uhden

0 Likes
Message 22 of 41

damian_dymczyk
Contributor
Contributor

Thanks for the help unfortunately I'm at the very beginning of the Autolisp journey and I don't know how to deploy your code. But nevertheless thank you for your commitment. 

0 Likes
Message 23 of 41

Sea-Haven
Mentor
Mentor

I used pedit and added a vertex to a pline and it maintained the handle ID, I did not check change the shape entirely that needed a vla-put-cordinates obj lst. Editing the pline using lisp can be done, CIV3D may chuck out the changes. So try a manual pedit and see what CIv3d does if ok come back and can help with the edit. Plenty here can do that for you. Will look further.

0 Likes
Message 24 of 41

Sea-Haven
Mentor
Mentor

Posts 15 seems the answer, still not sure CIV3D. You will need to try.

0 Likes
Message 25 of 41

kerrcad
Contributor
Contributor

Thanks so much!!

This copies all the object data and keeps the same handle.  Just a  bit more editing if the lwpls are changing widths, thicknesses along the way.   Not something I need, but easy enough to follow your example. 

0 Likes
Message 26 of 41

john.uhden
Mentor
Mentor

Just as I did width the bulges, you could expand my method to include widths (40 and 41).

Um, just how do you vary thickness?  🤔

Ya know it's funny with heavy polylines (which used to be the only kind decades ago).  I always wondered why if each vertex were a separate entity, why couldn't you change a vertex layer or color separately from its owner.  I think the answer is you just can't.

John F. Uhden

0 Likes
Message 27 of 41

kerrcad
Contributor
Contributor

In my search for the solution you provided, I mistakenly recalled seeing dxf code 91 as being used for thickness.  It's not.  It is a vertex identifier, although I have no idea what that means or how it is used.  Any information would be appreciated.

0 Likes
Message 28 of 41

john.uhden
Mentor
Mentor
@kerrcad
91 is stated as being a "vertex identifier" but since it appears to always
be 0, I think it is used for nothing. IOW, it is an Autodesk programmer's
mistake. That is unless there is some future for it.
It may have been created to hold the parameter number, but the help says
it's in the range of Boolean codes. Anyway, ignore it.

John F. Uhden

Message 29 of 41

J_Spurgeon
Enthusiast
Enthusiast

@Kent1Cooper wrote:

@Anonymous wrote:

Have you find a Way too do the same for 3dpolylines?


Have you tried it?  See Messages 7 & 8.

 

But since there were some suggestions and edits and further correction not yet incorporated, here's a consolidated version:

 

(defun c:repoly (/ source target)
  (setq
    source (vlax-ename->vla-object (car (entsel "\nSource Polyline: ")))
    target (vlax-ename->vla-object (car (entsel "\nTarget Polyline: ")))
  ); setq
  (vla-put-Coordinates target (vla-get-Coordinates source))
  (initget "Yes No")
  (if (= (getkword "\nDo you want to delete the source polyline? [Yes/No]: ") "Yes")
    (vla-delete source) ; then -- delete source polyline
  ); if
  (princ)
); defun

 


This works perfectly, thank you for sharing. 

 

I have been trying to figure out a way for this to run on a whole drawing that has two separate sets of lines on 2 different layers. Do you think it is possible to have it auto select the lines based on the geographic location and match them up to the line underneath them? Essentially I have a cable and a conduit layer that should match perfectly but after many hands have touched them they are no longer perfectly aligned. 

0 Likes
Message 30 of 41

john.uhden
Mentor
Mentor

@J_Spurgeon 

I am confused.  If your cable is going to be pigged and pulled inside the conduit, then it has nowhere else to go, so why do you need two alignments?

John F. Uhden

0 Likes
Message 31 of 41

J_Spurgeon
Enthusiast
Enthusiast
We use two separate alignments because we have to track each separately for BOM and GIS purposes. The conduit is normally a linear footage between structures and the cable passes through multiple structures without being cut.
0 Likes
Message 32 of 41

Kent1Cooper
Consultant
Consultant

@J_Spurgeon wrote:
.... a way for this to run on a whole drawing that has two separate sets of lines on 2 different layers. Do you think it is possible to have it auto select the lines based on the geographic location and match them up to the line underneath them? .... The conduit is normally a linear footage between structures and the cable passes through multiple structures without being cut.

Does that mean the cable Polylines are continuous through/under multiple separate conduit Polylines and maybe gaps between them through the structures?  In other words, are you talking about imposing vertices from one Polyline onto a portion of another one, or vertices from a portion of one Polyline onto the entirety of another one?  The code so far does all of one onto all of another.

Kent Cooper, AIA
0 Likes
Message 33 of 41

J_Spurgeon
Enthusiast
Enthusiast

@Kent1Cooper wrote:

@J_Spurgeon wrote:
.... a way for this to run on a whole drawing that has two separate sets of lines on 2 different layers. Do you think it is possible to have it auto select the lines based on the geographic location and match them up to the line underneath them? .... The conduit is normally a linear footage between structures and the cable passes through multiple structures without being cut.

Does that mean the cable Polylines are continuous through/under multiple separate conduit Polylines and maybe gaps between them through the structures?  In other words, are you talking about imposing vertices from one Polyline onto a portion of another one, or vertices from a portion of one Polyline onto the entirety of another one?  The code so far does all of one onto all of another.


There will be a longer pline (the fiber) on top of several shorter plines (the conduit). Their path should be identical but after several design changes and stuff I guess someone forgot to match them up. So now I am left with a ton of conduit that is just slightly off. There should be no gaps as the endpoints under the structures should all be snapped together (hopefully). 

 

I attached a small sample drawing of what I am talking about. 

0 Likes
Message 34 of 41

Kent1Cooper
Consultant
Consultant

@J_Spurgeon wrote:

....

There will be a longer pline (the fiber) on top of several shorter plines (the conduit). Their path should be identical ...

That's what I was afraid of....  Is the full-length blue one the "right" one, and you want the green ones to conform to it?  If there are no gaps between green ones, is it acceptable to join them all together into one?

Kent Cooper, AIA
0 Likes
Message 35 of 41

J_Spurgeon
Enthusiast
Enthusiast

@Kent1Cooper wrote:

@J_Spurgeon wrote:

....

There will be a longer pline (the fiber) on top of several shorter plines (the conduit). Their path should be identical ...

That's what I was afraid of....  Is the full-length blue one the "right" one, and you want the green ones to conform to it?  If there are no gaps between green ones, is it acceptable to join them all together into one?


That is correct, the full length one will always be the correct one. And ideally the shorter green ones will remain separated because they have independent object data that I would need to keep. 

0 Likes
Message 36 of 41

Kent1Cooper
Consultant
Consultant

I thought up a way to go about that, which worked for me in your sample drawing.  It counts on things always being as in that drawing [Layer names, all LWPolylines on those specific Layers, at zero elevation, etc.].  I can imagine it being fooled about the closest vertex in certain situations, for example with vertices in a short one being off by a greater distance than the lengths of short segments in the long one in that vicinity.  None of the usual enhancements yet, but see if it works mostly:

 

(defun C:FIXCONDUIT
  (/ ss UGss UG n cndt coords newcoords newpt)
  (if
    (and
      (setq ss (ssget '((0 . "LWPOLYLINE") (8 . "P_CABLE_DISTRIBUTION_UG,P_CONDUIT"))))
      (setq UGss (ssget "_P" '((8 . "P_CABLE_DISTRIBUTION_UG"))))
    ); and
    (progn ; then
      (setq UG (ssname UGss 0)); the long one
      (ssdel UG ss); remove it from the rest
      (command
        "_.layer"
          "_set" "P_CABLE_DISTRIBUTION_UG"
          "_off" "*" "_no" ; so Osnap won't find parts of Blocks, etc.
          "_on" "P_CONDUIT" ""
      ); command
      (repeat (setq n (sslength ss))
        (setq
          cndt (vlax-ename->vla-object (ssname ss (setq n (1- n))))
          coords (vlax-get cndt 'Coordinates)
          newcoords nil ; clear previous if any
        ); setq
        (repeat (/ (length coords) 2); number of vertices
          (setq
            newpt
            (vlax-curve-getPointAtParam UG
              (fix ; nearest vertex on long one
                (+
                  (vlax-curve-getParamAtPoint UG
                    (vlax-curve-getClosestPointTo UG (list (car coords) (cadr coords)))
                  ); ...getParam...
                  0.5
                ); +
              ); fix
            ); ...getPoint...
            newcoords (append newcoords (list (car newpt) (cadr newpt)))
            coords (cddr coords)
          ); setq
        ); repeat
        (vlax-put cndt 'Coordinates newcoords)
      ); repeat
      (command "_.layerp")
    ); progn
  ); if
  (prin1)
)

 

 

Kent Cooper, AIA
0 Likes
Message 37 of 41

J_Spurgeon
Enthusiast
Enthusiast
Wow, thank you! That actually works really well as long as I only have one fiber in my selection. If I grab 2 or more (to fix a whole area) it goes crazy.

I really appreciate you taking the time to write that for me. I have been trying to figure something out for a while.
0 Likes
Message 38 of 41

Kent1Cooper
Consultant
Consultant

@J_Spurgeon wrote:
... If I grab 2 or more (to fix a whole area) it goes crazy. ....

Do you think it can be assumed that all green ones associated with a given blue one will always at least be touched by that blue one somewhere, and that none associated with other blue ones will be?  If so, the selection could be for just those on the blue ones' Layer, and each of those could have its vertices used to define a Fence to select the pertinent green ones.  That would allow you to grab a whole area of multiple such groupings.

Kent Cooper, AIA
0 Likes
Message 39 of 41

J_Spurgeon
Enthusiast
Enthusiast
I think that would be safe to assume that, the only issue I could think of would be end points at intersections overlapping if someone did not snap it. But that should be few and far between. I was thinking the same thing but did not know how to execute it.

One other thing I noticed it doesn't play well with sometimes is arc segments of polylines.. I figured that would be the case though.. I hate messing with arcs, the bulges make everything difficult when trying to copy a path.
0 Likes
Message 40 of 41

CADaSchtroumpf
Advisor
Advisor

@J_Spurgeon  a écrit :
 If I grab 2 or more (to fix a whole area) it goes crazy.


Do your primary (blue) and secondary (green) fiber stubs have common object data (OD) for each path?
If so, it would be possible to filter the selections with this data by calling Map's lisp functions: (ade_odgetfield....)
This is so that each section is treated individually

0 Likes