Hatch - moving in model space

Hatch - moving in model space

OceanaPolynom
Advocate Advocate
535 Views
6 Replies
Message 1 of 7

Hatch - moving in model space

OceanaPolynom
Advocate
Advocate
Hello
I wrote a program that trys to move all the entities in a dwg file by calculating a grid transformation for each point in each entity. For example to move a pline
Code:   Case Is = "AcDb2dPolyline"
                Set o2DP = oEnt
                retCoord = o2DP.Coordinates
                For j% = 0 To UBound(retCoord) Step 3
                     yaa# = retCoord(j%)
                     xaa# = retCoord(j% + 1)
                     Call UTMCartGeo(yaa#, xaa#, latutm#, longutm#)
                     h# = Val(TextBoxH.Text)
                     Call UTMGEOtoITMGEO(latutm#, longutm#, h#, pp#, ll#)
                     Call ITMGeotoITMCart(pp#, ll#, e#, n#)
                     retCoord(j%) = e#
                     retCoord(j% + 1) = n#
                 Next j%
                 o2DP.Coordinates = retCoord

My problem is moving hatch entities. I haven't succeeded in finding equivalent code to move the hatch entities. I did find another post here, but I still don't get it.

Thank you
John

       

0 Likes
536 Views
6 Replies
Replies (6)
Message 2 of 7

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

just as a tip: if the hatches are set to assiciative ==> don't they update themselves after modifying there border-geomtries?

 

And for your prog: you have

  • Sub GetLoopAt(Index As Long, ObjectArray)
  • Sub InsertLoopAt(Index As Long, LoopType As AcLoopType, ObjectArray)
  • Property NumberOfLoops As Long

have you tried to play with these?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 7

OceanaPolynom
Advocate
Advocate

Hello

Thanks for replying.   Although the hatches are associative, only the boundary is moved, not the hatch.  GetLoopAt

returns the objects that are bounding the hatched area.  These objects are moved anyway by their respective Case IS=

sections of code.  So I'm still stuck.

 

Thank you

John

0 Likes
Message 4 of 7

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

what if you do a Hatch.Update after you moved the boundary-geomtries?

I have not enough time at the moment, so I can't spent time to do some testing now ... what if you just do your modifications to all geometry but not the hatches? Either then a Hatch.Update .... or in the drawing a REGEN?

If you don't update the hatches ... have they lost the associativity?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 7

OceanaPolynom
Advocate
Advocate

 

Hello

 

I will start to check your suggestions now.  

Thanks again

John 

0 Likes
Message 6 of 7

OceanaPolynom
Advocate
Advocate

Hello

Thanks to your helpfull suggestions I have solved (partly) my problem.  After first transforming all entities except hatches to their new grid location, the program recreates the hatch objects at the new locations, except in cases where the boundary entities hve been erased.  here is the hatch code:

 

'all entities except hatches have been transformed to their new locations by here

Dim fcode(0) As Integer
Dim fvalue(0) As Variant
fcode(0) = 0
fvalue(0) = "Hatch"
Dim groupCode As Variant, dataCode As Variant
groupCode = fcode
dataCode = fvalue
Dim ssetall As AcadSelectionSet
On Error Resume Next
A2K.ActiveDocument.SelectionSets.Item("sset").Delete
On Error GoTo 0
Set ssetall = A2K.ActiveDocument.SelectionSets.Add("sset")
'select all hatch objects
ssetall.Select acSelectionSetAll, , , groupCode, dataCode

For i = 0 To ssetall.Count - 1
      Set oEnt = ssetall.Item(i)
      Set oHatch = oEnt
      ' Find the objects that make up the first (outer) loop
      Dim loopType As Variant      
      Dim loopObjs As Variant      
      Dim outerLoop(0 To 0) As AcadEntity      
      Dim innerLoop(0 To 0) As AcadEntity      
             
      oHatch.GetLoopAt 0, loopObjs      

      ' Find the types of the objects in the loop      
      Dim Ii As Integer      
      Dim objName As String      
      For Ii = LBound(loopObjs) To UBound(loopObjs)      
          Set outerLoop(Ii) = loopObjs(Ii)      
      Next Ii      
      jk% = oHatch.NumberOfLoops      
      oHatch.AppendOuterLoop (outerLoop)      
      
      ' Find the objects that make up the each inner loop

      For lc% = 1 To jk% - 1      
            
          oHatch.GetLoopAt lc%, loopObjs      
          For Ii = LBound(loopObjs) To UBound(loopObjs)      
              Set innerLoop(Ii) = loopObjs(Ii)      
          Next Ii      
          oHatch.AppendInnerLoop (innerLoop)      
      Next lc%      

  oHatch.Evaluate	
      oHatch.Update      
Next i

 Attached are 2 dwg files.  Hatch6.dwg is the source file.  Hatch6UTM36N.dwg is the file created by the code.  Zoom extents on the results file reveals that while the hatches are restored at the new locations, the original hatch objects remain in place.  The hatch without the boundary object, does not move and will cause an error if not trapped.  Associativity is maintained at the new hatch locations.

 

Thank you

John

0 Likes
Message 7 of 7

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> except in cases where the boundary entities hve been erased

in that case you just could move the hatch, can't you? If the borders don't exist any more the hatch could not be associative any more (and so also does not have to be after your repositioning)

Or do you do any non-linear disortion?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes