Hi,
I'd like to automatically hatch all visible polygons of a drawing.
My vision of how to solve this is basically:
- for each visible drawing do
- pick internal point
- hatch
- end for
I'm having trouble by automatically picking an internal point inside the polygon.
I've found these two methods : Crossing numbers and winding numbers (http://geomalgorithms.com/a03-_inclusion.html) but they don't seem to work if there are some polylines inside an polygon. ( example a but like polygon lol I know ... I'm inspired today hahaa )
Is there another solution to my problem for automatically picking an internal point inside a polygon ? Can I automatically hatch an polygon without picking it's internal point ?
Thank you in advance for your help.
I aready have similar solution,
change hatch apttern and scale on whatever you need:
<CommandMethod("mhat", CommandFlags.Modal Or CommandFlags.Session)> _ Public Sub CreateHatchMulty() Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Try doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Using docloc As DocumentLock = doc.LockDocument Using tr As Transaction = doc.Database.TransactionManager.StartTransaction 'get active space Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord) Dim pso As PromptSelectionOptions = New PromptSelectionOptions pso.MessageForRemoval = vbLf + "Must be selected closed contours!" pso.MessageForAdding = vbLf + "Select contours: " pso.SingleOnly = False pso.SinglePickInSpace = False pso.PrepareOptionalDetails = True Dim filter As SelectionFilter = New SelectionFilter(New TypedValue() _ {New TypedValue(-4, "<or"), New TypedValue(-4, "<and"), New TypedValue(0, "lwpolyline"), New TypedValue(70, 1), _ New TypedValue(-4, "and>"), New TypedValue(0, "circle,,ellipse"), New TypedValue(-4, "or>")}) Dim res As PromptSelectionResult = ed.GetSelection(pso, filter) If res.Status <> PromptStatus.OK Then Return Dim sset As SelectionSet = res.Value If sset.Count = 0 Then Return Dim ent As Entity For Each sobj As SelectedObject In sset ent = TryCast(tr.GetObject(sobj.ObjectId, OpenMode.ForRead), Entity) If ent Is Nothing Then Return Dim hat As New Hatch() ' add hatch first btr.AppendEntity(hat) tr.AddNewlyCreatedDBObject(hat, True) hat.PatternAngle = 0.0 hat.PatternScale = 2.0 hat.Associative = True hat.SetHatchPattern(HatchPatternType.PreDefined, "ANSI32") ' append loop to hatch Dim dbObjIds As New ObjectIdCollection() dbObjIds.Add(sobj.ObjectId) hat.AppendLoop(HatchLoopTypes.External, dbObjIds) hat.Layer = ent.Layer hat.ColorIndex = 256 'bylayer, may use as per entity colorindex hat.HatchStyle = HatchStyle.Normal hat.EvaluateHatch(True) Next tr.Commit() 'commit the transaction so the changes get written to db End Using End Using doc.Editor.Regen() Catch ex As Autodesk.AutoCAD.Runtime.Exception Finally MsgBox("Pokey?") End Try End Sub
Thanks for your answers and the code however I always get "pokey?" meaning that it has ran into an exception, right ?
Remove this message from Finally... End Try code block,
it's just for display when the end is riched
But how it works for you?
Hi Hallex,
Sorry for my late answer, I was dealing with personnal problems.
When I execute your code it asks me to select a contour, which I do over rectangles and circles.
I reclick to specify opposite corner.
The console says : "3 found" meaning that the 3 rectangles are found but not the circles.
Then I press enter and ... nothing happens ... besides the 'pokey message'.
Do you have an idea on what is the problem ?
I'm sorry I cannot correct your code since I'm not a very good programmer but I'm learning.