How to creat Path Array in Autocad With C#

How to creat Path Array in Autocad With C#

quangpt.tric
Advocate Advocate
1,465 Views
2 Replies
Message 1 of 3

How to creat Path Array in Autocad With C#

quangpt.tric
Advocate
Advocate

Hello everybody,

I want creat a yellow polyline, and then path array it by white polyline as image below. Can any body tell me that how can I do it?

Thank you very much!

Capture.PNG

 

0 Likes
Accepted solutions (1)
1,466 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

So, you want to draw a series of short polylines of the same length along a path with an equal gap between them. So, the required inputs will be:

 

1. The path's length;

2. the segment's length;

3 the length of the gap;

 

With all these known, you can easily calculate each segment's start/end points, using

 

[PathPolyline].GetPointAtDist()

 

Pseudo-code:

void DrawingSegenebtsAlongPath(ObjectId pathId, double segLength, double setGap)

{

    using (var tran = [Open a transaction]

    {

       var path=(Polyline)tran.GetObjectpathId, OpenMode.ForRead);

       var currentLen=segLength;

       var startPt=path.StartPoint;

       while(currentLen < path.Length)

       {

           var endPt=path.GetPointAtDist(currentLen);

           // now you have both start/end point of a segment

           // draw the segment, add to database and transaction

           ... ...

 

           // increment the start point of next segment

           // then continue the loop

           currentLen+=segGap

           startPt=path.GetPointAtDist(currentLen);

           currentLen+=segLegth

       }

 

       // after the loop ends, you will decide if you need to draw

       // a last segment with its length less than segLength, so that the total 

       // currentLen equals the path.Length; or you draw a a full-length segment

       // so that the segment array will slightly longer than the path.Length

       ... ...

 

        tran.Commit();

    }

}

 

As you can see, if there is a path curve exists, you can take advantage of GetPointAtDist() to make the calculation much easier. But depending on your business workflow, if the path is straight, you do not even need a path (polyline/line). Providing 2 points would be enough to apply your math knowledge to do the calculation of each segment's start/end point and draw them.

 

If you create your own command to let user to draw it, I'd imagine that you could make it a good user-friendly command in "Jig" style: user pick a point, while the mouse moves, a series of ghost segments shows with default segment length/gap, user could either enter different segment length/gap, or pick another point to actually draw the segments.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

quangpt.tric
Advocate
Advocate

Hi @norman.yuan ,

Thank you for your support code. Your code is all things I need. You are a legend!

0 Likes