.NET

Reply
Active Member
suisse_power
Posts: 9
Registered: ‎02-06-2013
Message 1 of 6 (316 Views)

Hatch all visible entities

316 Views, 5 Replies
02-06-2013 09:51 AM

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.

 

*Expert Elite*
_gile
Posts: 2,086
Registered: ‎04-29-2006
Message 2 of 6 (303 Views)

Re : Hatch all visible entities

02-06-2013 10:50 AM in reply to: suisse_power

 

Spoiler
Can I automatically hatch an polygon without picking it's internal point ?

 

For sure ! Look at the Hatch.AppendLoop(HatchLoopTypes, loopType, ObjectIdCollection ids) method:

 

Gilles Chanteau
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 6 (279 Views)

Re: Hatch all visible entities

02-07-2013 08:47 AM in reply to: suisse_power

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

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Member
suisse_power
Posts: 9
Registered: ‎02-06-2013
Message 4 of 6 (260 Views)

Re: Hatch all visible entities

02-09-2013 05:56 AM in reply to: Hallex

Thanks for your answers and the code however I always get "pokey?" meaning that it has ran into an exception, right ?

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 6 (245 Views)

Re: Hatch all visible entities

02-10-2013 12:22 PM in reply to: suisse_power

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?

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Member
suisse_power
Posts: 9
Registered: ‎02-06-2013
Message 6 of 6 (209 Views)

Re: Hatch all visible entities

03-01-2013 09:23 AM in reply to: Hallex

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.

 

 

 

 

 

 

 

 

 

 

 

 

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 or visit the Installation and Licensing Forum to get help installing your software.