.NET

Reply
Distinguished Contributor
223 Posts
0 Kudos
Registered: ‎02-17-2006
Post 1 of 4

Problems with automated hatching.

101 Views, 3 Replies
02-27-2006 04:04 PM
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. :smileywink:
Distinguished Contributor
223 Posts
0 Kudos
Registered: ‎02-17-2006
Post 2 of 4

Re: Problems with automated hatching.

02-28-2006 09:55 AM 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
Distinguished Contributor
125 Posts
0 Kudos
Registered: ‎08-02-2005
Post 3 of 4

Re: Problems with automated hatching.

02-28-2006 01:53 PM 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
Distinguished Contributor
223 Posts
0 Kudos
Registered: ‎02-17-2006
Post 4 of 4

Re: Problems with automated hatching.

03-02-2006 09:41 AM 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.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!