.NET

Reply
Distinguished Contributor
jbooth
Posts: 223
Registered: ‎02-17-2006
Message 1 of 4 (96 Views)

Problems with automated hatching.

96 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
jbooth
Posts: 223
Registered: ‎02-17-2006
Message 2 of 4 (96 Views)

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
cgay
Posts: 125
Registered: ‎08-02-2005
Message 3 of 4 (96 Views)

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
jbooth
Posts: 223
Registered: ‎02-17-2006
Message 4 of 4 (96 Views)

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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community