.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Boundary and hatch by api

4 REPLIES 4
Reply
Message 1 of 5
hcaddev
1154 Views, 4 Replies

Boundary and hatch by api

Hello everyone,

I'd like to know if there is any possibility to get a boundary and a hatch by the api and not by SendCommandToExecute.
I found a blog post from Kean Walmsley which shows a way to get a hatch by giving the method a closed curve but that's my problem. I do not have curve.
I'd like to start a command by the api that asks the user to select a point in the boundary and gets the boundary lines. In the best way the lines include their layer.
I need that boundary and want to insert a hatch into that. I need the hatch lines later on, too.

The only way I found:
{code}
string testString = "_-hatch\r_A\r_R\r_Y\r_S\r_O\r_B\r_N\r_P\r\r\r";
Application.DocumentManager.MdiActiveDocument.CommandEnded += OnCommandEnd;
SendStringToExecute(testString, true, false, false);
...

public static void OnCommandEnd(Object sender, CommandEventArgs e)
{
if (e.GlobalCommandName.Equals("-HATCH"))
{
Document doc = (Document) sender;
Hatch hatch = GetHatchFromDocument(doc);
List hatchLoops = GetHatchLoops(hatch);
Line2dCollection hatchLinesData = hatch.GetHatchLinesData();
}
}

private static Hatch GetHatchFromDocument(Document doc)
{
ObjectId lastObjectId = new ObjectId();
List ids = new List();
using (var db = doc.Database)
{
using (Transaction transaction = db.TransactionManager.StartTransaction())
{
try
{
BlockTable blockTable =
(BlockTable)
transaction.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId,
OpenMode.ForRead);
BlockTableRecord modelSpace =
(BlockTableRecord)
transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);
var enumerator = modelSpace.GetEnumerator();

while (enumerator.MoveNext())
{
lastObjectId = enumerator.Current;
ids.Add(enumerator.Current);
}

Entity ent = (Entity) transaction.GetObject(lastObjectId, OpenMode.ForRead);
transaction.Commit();

if (ent is Hatch)
{
Hatch hatch = (Hatch) ent;
return hatch;
}
return new Hatch();
}
catch (Exception ex)
{

throw new InvalidOperationException("AreaFunctions.GetHatchFromDocument()", ex);
}
}
}
}

private static List GetHatchLoops(Hatch hatch)
{
List hatchLoops = new List();
for (int loopIndex = 0; loopIndex < hatch.NumberOfLoops; loopIndex++)
{
HatchLoop hatchLoop = hatch.GetLoopAt(loopIndex);
hatchLoops.Add(hatchLoop);
}
return hatchLoops;
}
{code}

If I do it that way I have to split my code with the command end event to get in sync. But then I get the problems that the Line2dCollection does only contain Line2d objects without start point and end point. I just get PointOnLine and Direction. But how can I get at least the length to get the complete line? I found line.GetLength(double fromParameter, double toParameter) but what are those parameters?

The hatchLoops does not contain the layer of the boundary because they are newly created objects. So I can just convert the BulgeVertices from the HatchLoop Polyline into lines. Is there then a way to find the line that is overlapped by that line? Maybe something line inquiry(Point) which gets me the line at that point?

Is there any better way to do this?
Thanks in advanced to answer all my questions.

Best regards
Kai
4 REPLIES 4
Message 2 of 5
kbarnettza
in reply to: hcaddev

Kai,
Did you find the answer? I have the same question, in a different place. I was going to use Curve2d.GetLength to get the arc length of an arc segment in a polyline2d but - like you - I do not know what the from and to input parameters are.
Message 3 of 5
hcaddev
in reply to: hcaddev

Kevin,

I'm using it like this double

{code}
double length = line2dObject.GetLength(0, 1);
{code}

I still don't know what those parameters exactly are but I get the length I need. Edited by: hcaddev on Mar 5, 2010 7:40 AM
Message 4 of 5
Anonymous
in reply to: hcaddev

On 3/5/2010 1:40 AM, hcaddev wrote:
> I still don't know what those parameters exactly are but I get the length I need.

The parameters refers to a point along the curve where the parameter 0
is one end point and 1 is the other. This means a parameter of 0.5 is
the midpoint.
Note that this applies to ANY curve: circles, arcs, parabolic, etc.

---
Joel Lucsy
CAD fx
810-732-0085 or 877-741-2175
http://www.cadfx.com
Message 5 of 5
_gile
in reply to: hcaddev

Hi,

> Note that this applies to ANY curve: circles, arcs, parabolic, etc.
This is not true.

- line parameter is equal to the length from start point
- polyline parameter is incemented by 1 at each vertex and digits corresponds to the segment fraction (i.e. 2.5 is the middle of the 3rd segment)
- arc and circle parameters corresponds to the angle in radians
- ellipse paramter is an angle measured from the major axis so that the X and Y coordinates of a point on the ellipse (coordinates expressed in the 'ellipse coordinate system' which X axis is major axis and Y axis minor axis) are respectively equal to: (majAxis/2) * cos(angle) and (minAxis/2) * sin(angle). You can have a look here:
http://discussion.autodesk.com/forums/click.jspa?searchID=11108122&messageID=6134944.
- spline parameter is much more complex, I still can't completely understand how it works.

Try this on different curves
{code}[CommandMethod("PARAM")]
public static void Param()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a curve: ");
peo.SetRejectMessage("\nNot a curve");
peo.AddAllowedClass(typeof(Curve), false);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Curve crv = (Curve)tr.GetObject(per.ObjectId, OpenMode.ForRead);
Point3d pt = per.PickedPoint.TransformBy(ed.CurrentUserCoordinateSystem);
pt = crv.GetClosestPointTo(pt, false);
ed.WriteMessage("\nParameter at pick point: {0}", crv.GetParameterAtPoint(pt));
}
}{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost