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

Problems with automated hatching.

3 REPLIES 3
Reply
Message 1 of 4
jbooth
345 Views, 3 Replies

Problems with automated hatching.

While trying to automate hatching, I've come across two problems:

1. My hatches will not draw on the screen unless I specify the "Solid" fill pattern. If I try to select the hatch objects, the application crashes.

2. If I try to set the Associative of the DatabaseServices.Hatch object I create, I get an error: 'eNotInDatabase'.


Are there any links around that show how to properly add hatch objects to the database? I would prefer something that uses existing geometry for the hatch boundaries, but anything that actually works as intended would be a great help.

Thanks,
JB

ps: I have attached a simplified version of what I was trying to get working. Maybe by taking a look at it someone will see what I'm doing wrong. 😉
3 REPLIES 3
Message 2 of 4
jbooth
in reply to: jbooth

I've solved problem #1 by calling the EvaluateHatch() method of the Hatch class before I add it to the database.

I would still like to get help with my second problem (hatch associativity).

Thanks
Message 3 of 4
cgay
in reply to: jbooth

Jason,

Try this.....For VB.Net 2005.......

[code]
Private Shared Sub Hatch(ByVal obj As AcadDB.ObjectId)
Dim db As AcadDB.Database = AcadApp.DocumentManager.MdiActiveDocument.Database
Dim tm As AcadDB.TransactionManager = db.TransactionManager
Dim NewID As AcadDB.ObjectId = AcadDB.ObjectId.Null
Using myT As AcadDB.Transaction = tm.StartTransaction()
Try
Using table As AcadDB.BlockTable = TryCast(myT.GetObject(db.BlockTableId, AcadDB.OpenMode.ForRead, False), AcadDB.BlockTable)
Using record As AcadDB.BlockTableRecord = TryCast(myT.GetObject(table(AcadDB.BlockTableRecord.ModelSpace), AcadDB.OpenMode.ForWrite, False), AcadDB.BlockTableRecord)
Dim o As AcadDB.Entity = DirectCast(myT.GetObject(obj, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, False), AcadDB.Entity)
Dim h As New AcadDB.Hatch()
h.SetDatabaseDefaults()
h.Layer = o.Layer
o.Dispose()
h.HatchStyle = Autodesk.AutoCAD.DatabaseServices.HatchStyle.Normal
h.SetHatchPattern(Autodesk.AutoCAD.DatabaseServices.HatchPatternType.PreDefined, "ANSI31")
Dim oID As AcadDB.ObjectId = record.AppendEntity(h)
If oID.IsValid Then
NewID = oID
h.Associative = True
myT.AddNewlyCreatedDBObject(h, True)
myT.Commit()
Else
myT.Abort()
End If
End Using
End Using
Catch ex As Exception
myT.Abort()
End Try
End Using
If NewID <> AcadDB.ObjectId.Null Then
Using myT As AcadDB.Transaction = tm.StartTransaction()
Try
Dim h As AcadDB.Hatch = DirectCast(myT.GetObject(NewID, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, False), AcadDB.Hatch)
Dim mylist As New AcadDB.ObjectIdCollection(New AcadDB.ObjectId() {obj})
h.AppendLoop(AcadDB.HatchLoopTypes.Default, mylist)
h.EvaluateHatch(False)
h.Dispose()
myT.Commit()
Catch ex As Exception
myT.Abort()
End Try
End Using
End If
tm.Dispose()
db.Dispose()
End Sub
[/code]
Start Transaction
Step 1. Create the hatch object
Step 2. Setup how the hatch will look
Step 3. Add it to the Block Table record
Step 4. Now, assign the associativity
Step 5. Let the transaction know of the new object and commit
End Transaction
Start Transaction
Step 6. Open the hatch object and append the loops
Step 7. Evaluate
Step 8. Commit
End Transaction

Hope this is what you are looking for. I found this info out from trial and error and also reading the ObjectARX 2006 documentation on "AcDbHatch::setAssociative Function".

Good Luck,
C
Message 4 of 4
jbooth
in reply to: jbooth

Actually, I figured it out on my own and forgot to post about it.

To set the associativity of a hatch, both the hatch and the boundary loops need to be in the database.

Therefore, simply add the hatch to the db before you call Hatch.AppendLoop() and before you set Hatch.Associative = True. The same thing applies to block and attribute references.

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