The code in the previous post has a few problems,
and doesn't support internal loops.
This version should be better at doing what you need:
{code}
public static class CurveExtensionMethods
{
public static bool IsClosedCurveHatched( this Curve curve )
{
if( curve.Closed )
{
RXClass hatchClass = RXClass.GetClass( typeof( Hatch ) );
using( Transaction tr =
curve.Database.TransactionManager.StartTransaction() )
{
try
{
var hatches = from id in
curve.GetPersistentReactorIds().Cast()
where id.ObjectClass.IsDerivedFrom(
hatchClass )
select id.GetObject(
OpenMode.ForRead ) as Hatch;
foreach( Hatch hatch in hatches )
{
int loops = hatch.NumberOfLoops;
for( int i = 0; i < loops; i++ )
{
if( hatch.LoopTypeAt( i ) == HatchLoopTypes.Outermost )
{
ObjectIdCollection ids =
hatch.GetAssociatedObjectIdsAt( i );
return ids.Count == 1 && ids[0] == curve.ObjectId;
}
}
}
}
finally
{
tr.Commit();
}
}
}
return false;
}
}
{code}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com
Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
"Tony Tanzillo" wrote in message
news:6236194@discussion.autodesk.com...
The API you're calling is 'GetPersistentReactorIds', which means
that it isn't going to get the actual reactor objects, just their objectIds.
So you must do one of two things:
On AutoCAD 2009 or later, you can look at each ObjectId's
ObjectClass property to see if it is the RXClass for the Hatch
object.
On older releases, you must open each ObjectId and try to
cast the DBObject to a Hatch object.
The other thing to beware of is that just because a Hatch is a
persistent reactor on an object doesn't necessarily mean the
object is 'hatched', it only means the object defines part of the
boundary of a hatch, and it can be used as a boundary for more
than one hatch as well.
You would have to examine the hatch to see what other objects
may also be used for the boundary, and if there's only the single
object and its closed, then you can assumed that it's 'hatched'.
Here is an extension method for the Curve class that should
answer the question (sorry, this is C#):
{code}
public static class CurveExtensionMethods
{
// returns true if the parameter's interior is completely
// hatched (e.g., there are no internal loops).
public static bool IsClosedCurveHatched( this Curve curve )
{
if( curve.Closed && curve.Database != null )
{
RXClass hatchClass = RXClass.GetClass( typeof( Hatch ) );
using( Transaction tr =
curve.Database.TransactionManager.StartTransaction() )
{
var hatches = from id in
curve.GetPersistentReactorIds().Cast()
where id.ObjectClass.IsDerivedFrom(
hatchClass )
select id.GetObject( OpenMode.ForRead ) as
Hatch;
foreach( Hatch hatch in hatches )
{
if( hatch.Associative && hatch.NumberOfLoops == 1 )
{
ObjectIdCollection assocIds =
hatch.GetAssociatedObjectIds();
if( assocIds.Count == 1 && assocIds[0] == curve.ObjectId )
return true;
}
}
tr.Commit();
}
}
return false;
}
}
{code}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com
Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:6235936@discussion.autodesk.com...
I have an VB.NET app that I has to programically hatch polylines...The
following code works fine except I need to first test if the polyline
already has a hatch associated with it so that another hatch is not added.
Apparantly I need to use the GetPersistentReactorIds method to retrieve the
ObjectIDs of the entity. However the test I included below does not find any
hatch when I test the code and select a polyline with a hatch.
Any sample code to do this or guidance is appreciated.
Public Sub TestHatch()
' method was gleaned from ObjectArx2006 samples, file
EntMakeTest.cpp
'
Dim db As Database =
Application.DocumentManager.MdiActiveDocument.Database
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
Dim selOpts As New PromptSelectionOptions()
Dim res As PromptSelectionResult
selOpts.SingleOnly = True
selOpts.MessageForAdding = "Select a closed polyline"
res = ed.GetSelection(selOpts)
If Not res.Status = PromptStatus.OK Then Return
Dim selId As ObjectId = res.Value.GetObjectIds(0)
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager =
db.TransactionManager
Dim trans As Transaction = tm.StartTransaction
Try
Dim objIds As New ObjectIdCollection()
objIds.Add(selId)
Dim hat As New Hatch()
With hat
.SetDatabaseDefaults()
'.Layer = "0"
.PatternAngle = 0.0
.PatternScale = 1.0 '
.SetHatchPattern(HatchPatternType.PreDefined, "SOLID")
End With
Dim bt As BlockTable =
CType(trans.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable)
Dim btr As BlockTableRecord =
CType(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite,
False), BlockTableRecord)
'Check if Object already has hatch associated with it
For Each objId As Object In btr.GetPersistentReactorIds()
ed.WriteMessage((ControlChars.Lf + "Object selected has
: " + objId.GetType().FullName))
Next
btr.AppendEntity(hat)
trans.AddNewlyCreatedDBObject(hat, True)
hat.Associative = True
hat.AppendLoop(CType(1, HatchLoopTypes), objIds)
hat.EvaluateHatch(False)
hat.Dispose()
trans.Commit()
Catch ex As Exception
MsgBox(ex.Message)
trans.Abort()
Finally
trans.Dispose()
tm.Dispose()
End Try
End Sub