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

Migrate VBA to VB Hatch

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
1285 Views, 2 Replies

Migrate VBA to VB Hatch

All,

I have an old vba routine that I don't have time right now to learn how to
rewrite in dot net. I'm looking for help adding soild hatch to the objpline.
I've added a thisdrawing property which I thought would allow me to
use my existing vba code until I learned how to translate all the items to
dot net but I'm getting an error setting the hatch to a solid pattern. all
other items seem to be working.

In vba I've used this for years. What is the equivalent in dot net to set a
solid hatch pattern?
Set objHatch = ThisDrawing.ModelSpace.AddHatch(acHatchPatternTypePreDefined,
"SOLID", True)

Thanks
John Coon


If CheckBox1 = True Then
Dim objHatch As AcadHatch
Dim objPline As AcadLWPolyline
Dim outerLoop(0 To 0) As AcadEntity

Set objPline =
ThisDrawing.ModelSpace.AddLightWeightPolyline(approachpoints1)
objPline.Closed = True
Set objHatch = ThisDrawing.ModelSpace.AddHatch(acHatchPatternTypePreDefined,
"SOLID", True)
Set outerLoop(0) = objPline
objHatch.AppendOuterLoop outerLoop
objHatch.Evaluate
objPline.Delete

End If
2 REPLIES 2
Message 2 of 3
Hallex
in reply to: Anonymous

This one is from my working code
See if that helps
{code}
Public Function AddHatch(ByVal dbObjIds As ObjectIdCollection) As ObjectId
Dim doc As Document = AcadApp.DocumentManager.MdiActiveDocument
Dim docklock As DocumentLock = doc.LockDocument()
Dim db As Database = HostApplicationServices.WorkingDatabase()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor()
Dim pHatch As New Hatch
Using tr As Transaction = db.TransactionManager.StartTransaction
Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

'Append newly created hatch to database
btr.AppendEntity(pHatch)
tr.AddNewlyCreatedDBObject(pHatch, True)
'Set hatch plane, normal, elevation
Dim norm As Vector3d = New Vector3d(0.0, 0.0, 1.0)
pHatch.Normal = norm
pHatch.Elevation = 0.0
'Set hatch layer to "0"
pHatch.Layer = "0"
'Set hatch color to 252
pHatch.ColorIndex = 252
'Set hatch scale to 2
pHatch.PatternScale = 2.0
'Set hatch angle to 45 deg
pHatch.PatternAngle = Math.PI / 4
'Set hatch pattern to EARTH predefined type
pHatch.SetHatchPattern(HatchPatternType.PreDefined, "EARTH")
'Set Associativity
pHatch.Associative = False 'optional?
'Append an external contour loop to hatch boundary
pHatch.AppendLoop(HatchLoopTypes.External, dbObjIds)
'Elaborate hatch contour
pHatch.EvaluateHatch(True)
'Commit transaction
tr.Commit()
End Using
docklock.Dispose()
Return pHatch.ObjectId
End Function
{code}

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 3
Anonymous
in reply to: Anonymous

hallex.

I'll give it a try. Can I use the thisdrawing and transactions in the same
routine?
have not used the transaction code yet, only migrated thisdrawing calls
until I learn dot net.

Thanks, I give it a try.

john Coon

"hallex" wrote in message news:6351593@discussion.autodesk.com...
This one is from my working code
See if that helps
{code}
Public Function AddHatch(ByVal dbObjIds As ObjectIdCollection) As
ObjectId
Dim doc As Document = AcadApp.DocumentManager.MdiActiveDocument
Dim docklock As DocumentLock = doc.LockDocument()
Dim db As Database = HostApplicationServices.WorkingDatabase()
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor()
Dim pHatch As New Hatch
Using tr As Transaction = db.TransactionManager.StartTransaction
Dim btr As BlockTableRecord =
CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

'Append newly created hatch to database
btr.AppendEntity(pHatch)
tr.AddNewlyCreatedDBObject(pHatch, True)
'Set hatch plane, normal, elevation
Dim norm As Vector3d = New Vector3d(0.0, 0.0, 1.0)
pHatch.Normal = norm
pHatch.Elevation = 0.0
'Set hatch layer to "0"
pHatch.Layer = "0"
'Set hatch color to 252
pHatch.ColorIndex = 252
'Set hatch scale to 2
pHatch.PatternScale = 2.0
'Set hatch angle to 45 deg
pHatch.PatternAngle = Math.PI / 4
'Set hatch pattern to EARTH predefined type
pHatch.SetHatchPattern(HatchPatternType.PreDefined, "EARTH")
'Set Associativity
pHatch.Associative = False 'optional?
'Append an external contour loop to hatch boundary
pHatch.AppendLoop(HatchLoopTypes.External, dbObjIds)
'Elaborate hatch contour
pHatch.EvaluateHatch(True)
'Commit transaction
tr.Commit()
End Using
docklock.Dispose()
Return pHatch.ObjectId
End Function
{code}

~'J'~

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