extract boundary of hatch

extract boundary of hatch

Anonymous
Not applicable
3,609 Views
34 Replies
Message 1 of 35

extract boundary of hatch

Anonymous
Not applicable
ive found an autolisp to extract the boundary of a hatch

http://www.spaug.org/Public_Files/AutoLISP/HatchB.Zip

but in VBA it cant be done if boundary was deleted

hatchObj.GetLoopAt J, loopObjs

this only works with existing objects used as loops/boundary

so, is there any way to extract DXF codes/lists of an object and work in VBA with them?

i dont want to work with LISP, is a very extrange language for me
0 Likes
3,610 Views
34 Replies
Replies (34)
Message 21 of 35

Anonymous
Not applicable
aaahhhhhh, now ive got problems with ErrHandler, is not defined, is it a private type, a err object?

this is the way im trying to test your class

Dim Ci_Hatch As New Ci_Hatch
Dim oObject As AcadObject
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
Dim DXFMatches As MatchCollection
Dim DXFMatch As Match
Dim Rexp As New RegExp
Dim DXFstr As String
Dim i As Integer
Dim submatch As Variant

DXFstr = FSO.GetFile("C:\puntos.dxf").OpenAsTextStream.ReadAll
Rexp.Global = True
Rexp.MultiLine = True
Rexp.IgnoreCase = True
Rexp.Pattern = "\n\s\s0\r\n((HATCH)[A-Z\d]*)\r\n\s\s5\r\n([\dA-F]*)(.*[\r\n](?! 10))*330\r\n([\dA-F]*)(.*[\r\n](?! 10))*((.*[\r\n](?! 0))*)"
Set DXFMatches = Rexp.Execute(DXFstr)
If Not DXFMatches.COUNT = 0 Then
For Each DXFMatch In DXFMatches
If Not DXFMatch.SubMatches.COUNT = 0 Then
For Each submatch In DXFMatch.SubMatches
If IsNumeric(submatch) Then Set oObject = ThisDrawing.HandleToObject(CStr(submatch))
Next submatch
End If
MsgBox DXFMatch.value
Ci_Hatch.Read oObject, DXFMatch.value
Next DXFMatch
End If
0 Likes
Message 22 of 35

Anonymous
Not applicable
the handle string is not always a numeric value, so this will not work sometimes

f IsNumeric(submatch) Then Set oObject = ThisDrawing.HandleToObject(CStr(submatch))

so, is the handle string on a particular position of the submatches collection?
0 Likes
Message 23 of 35

Anonymous
Not applicable
Yes... Position (1)

And jusyt remove the ErrorHandler lines.... you dont need them....
0 Likes
Message 24 of 35

Anonymous
Not applicable
it gimme Object variable or With block variable not set (Error 91) in hatchloop buildreflist, and them gives error on other subs of hatchloop

the test seems to be OK

Dim Ci_Hatch As New Ci_Hatch
Dim oObjectHatch As AcadObject
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
Dim DXFMatches As MatchCollection
Dim DXFMatch As Match
Dim Rexp As New RegExp
Dim DXFstr As String
Dim i As Integer
Dim submatch As Variant
Dim sHatch As String, sHandle As String
Dim iCountMatch As Long, iCountSubMatch As Long

DXFstr = FSO.GetFile("C:\hatch.dxf").OpenAsTextStream.ReadAll
Rexp.Global = True
Rexp.MultiLine = True
Rexp.IgnoreCase = True
Rexp.Pattern = "\n\s\s0\r\n((HATCH)[A-Z\d]*)\r\n\s\s5\r\n([\dA-F]*)(.*[\r\n](?! 10))*330\r\n([\dA-F]*)(.*[\r\n](?! 10))*((.*[\r\n](?! 0))*)"
Set DXFMatches = Rexp.Execute(DXFstr)
If Not DXFMatches.COUNT = 0 Then
iCountMatch = 0
For Each DXFMatch In DXFMatches
If Not DXFMatch.SubMatches.COUNT = 0 Then
iCountSubMatch = 0
For Each submatch In DXFMatch.SubMatches
Debug.Print "Match " & iCountMatch & ", SubMatch " & iCountSubMatch & ":" & submatch
iCountSubMatch = iCountSubMatch + 1
Next submatch
sHandle = CStr(DXFMatch.SubMatches(2))
Set oObjectHatch = ThisDrawing.HandleToObject(sHandle)
If Not (TypeName(oObjectHatch) = "IAcadHatch2" Or TypeName(oObjectHatch) = "IAcadHatch") Then
MsgBox "Failed to handle object": Exit Sub
End If
End If
sHatch = CStr(DXFMatch.value)
Ci_Hatch.Read oObjectHatch, sHatch
iCountMatch = iCountMatch + 1
Next DXFMatch
End If

ive added Microsoft XML, v4.0 as reference, testing with a simple non associative hatch using a polyline as outerloop
0 Likes
Message 25 of 35

Anonymous
Not applicable
The buildRefList is not necessary. Take a look at the Read and CreateBoundaries functions... if its not called by one of thoses functions, you don't need it.

Actualy in the Read, just remove all lines between the 2 ('---------------------------Ref list). They were used for other purpuse.
0 Likes
Message 26 of 35

Anonymous
Not applicable
this starts to work, but in this example the polyline coordinates (boundary created) are not the coordinates of the polyline of hatch
the hatch is the little one on the left-bottom corner of the drawing (hatch.dxf)

maybe a decimal symbol problem? how could i read the full xml document? i would like to check the data organization of xml for debuggin

if anyone wanna test it must change this kind of lines

Set ArcObj = ThisDrawing.Blocks(mSpaceType).AddArc(Centre, mRadius, mStartAngle, mEndAngle)

to
Set ArcObj = ThisDrawing.ModelSpace.AddArc(Centre, mRadius, mStartAngle, mEndAngle)

i still didnt change all of them
0 Likes
Message 27 of 35

Anonymous
Not applicable
Did you give it the right DXF block? My best guess is that you did not give it the right DXF block for the entity that you passed. (not the same handle?). I think its the only possibility.

If you want, just post your project and I'll fix it in about 5 min. (I have been working with these classes for the past year, I know them real well.......!

And thats right.... forgot to tell you that you must use the SpaceType property to specify the container where you want those boundaries to be created (name of a block, or "*Model_Space"....).
0 Likes
Message 28 of 35

Anonymous
Not applicable
Ok... something is wrong here.

This works well. Just remove the big Polyline, then Zoom Extent and you will see your hatch and its contour around it. Perfect.
I realy didn't change anything in your code and it worked perfectly. And why is that big polyline doing there?

Anyway, this works.
0 Likes
Message 29 of 35

Anonymous
Not applicable
that big polyline is the boundary created when i run the vba

so, if it works for you, now im sure it must be a question about decimal symbol in the data flow from dxf-xml-autocad

you know, sometimes 12,546589 finally turn 12546589, so thats why this big polyline is there, it should be the little polyline inside the hatch

ill try to change decimal symbol and test again
0 Likes
Message 30 of 35

Anonymous
Not applicable
No, sorry, thats not it....

Just try it. Delete that big polyline and execute the code. The big polyline wont reapere..... or if it is, the code is different than what you gave me.
0 Likes
Message 31 of 35

Anonymous
Not applicable
Here are the exact steps I took:

1) Load the drawing and VBA project
2) Erase the big polyline
3) Zoom extents
4) Change the path of the DXF file in the sub test in the Module
5) Execute

That works perfectly..... let me know.
0 Likes
Message 32 of 35

Anonymous
Not applicable
test this:
Control Panel/Regional and
Languages Options/Customize: English (USA)
then it works perfect
now change to
Control Panel/Regional and
Languages Options/Customize: Español (España)
try again and you will see the big polyline

in DDCH server scripting, when working with dates, we use to fix this using 'setlocale', but dont know if this function is available in VBA
also dont know where the decimal symbol change, if it is in dxf or xml, thats why i wanted to read the xml
0 Likes
Message 33 of 35

Anonymous
Not applicable
Found it!!!

You were right!

The problem is that AutoCAd does not follow the system's format. But since I'm going "back door", I end up being affected by the computer's configs.

Solution:
In Ci_Hatch-ReadBoundaries, after the 3 Replace statements, add this one:

DXFBlock = Replace(DXFBlock, ".", ",")

And its fixed.......!
0 Likes
Message 34 of 35

Anonymous
Not applicable
ah, ok, i have fixed it this way

LCID = GetSystemDefaultLCID
sDecimalSep = GetUserLocaleInfo(LCID, LOCALE_SDECIMAL)
If Not sDecimalSep = "." Then Call SetLocaleInfo(LCID, LOCALE_SDECIMAL, ".")

the full code with GetLocaleInfo,SetLocaleInfo functions are in the attached file

now i want to automatize all process in VBA:
1.- select the hatchs in a DWG to recover boundaries
2.-open a new drawing and copy the hatchs selection on it
3.-save the new drawing as dxf
4.- read the dxf and operate over the original DWG

ill post when having something done (or may when having a question, hehe)
thanks again
0 Likes
Message 35 of 35

Anonymous
Not applicable
this is working perfectly when selecting one hatch, test it
it makes the 4 operations listed in my previous post

but when selecting 2 hatchs appears the error: index out of range in Ci_Hatch.Read

any idea?
0 Likes