Auto Hatch entities with execution error
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Auto Hatch entities with execution error

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
GerardK
Guest





Posted: Fri Jan 07, 2005 1:56 am    Post subject: Auto Hatch entities with execution error Reply with quote

Hello all,

When running this code, autocad (2004) gives me a Execution error.
This error comes from "For Each objAcadEntity In objSSet, next".
How can I solve this problem??

Newby on VBA,
Gerard

'Public Sub MakeHatchesFromLayer(myLayerName As String)
Dim arrOuterLoop(0) As AcadEntity
Dim objAcadHatch As AcadHatch
Dim objSSet As AcadSelectionSet
Dim objAcadEntity As AcadEntity
Dim gpCode(0 To 1) As Integer
Dim gpValue(0 To 1) As Variant

On Error GoTo ErrMakeHatchesFromLayer:

Set objSSet = ThisDrawing.SelectionSets.Add("SSet_MakeHatches")

gpCode(0) = 8: gpValue(0) = myLayerName
gpCode(1) = 0: gpValue(1) = "LWPOLYLINE"
objSSet.Select acSelectionSetAll, , , gpCode, gpValue

For Each objAcadEntity In objSSet ''''''''''ERROR why ??
If objAcadEntity.Closed Then
Set arrOuterLoop(0) = objAcadEntity
Set objAcadHatch = ThisDrawing.ModelSpace.AddHatch(acHatchPatternTypePreDefined, "SOLID", True)

objHatch.AppendOuterLoop objPline

objAcadHatch.AppendOuterLoop arrOuterLoop
objAcadHatch.Evaluate
objAcadHatch.Layer = myLayerName
End If
Next

ExitErrMakeHatchesFromLayer:
objSSet.Delete
Exit Sub

ErrMakeHatchesFromLayer:

MsgBox "Error : " & Err.Number & " - " & Err.Description
GoTo ExitErrMakeHatchesFromLayer:
End Sub

Back to top
Ed Jobe
Guest





Posted: Fri Jan 07, 2005 2:07 am    Post subject: Re: Auto Hatch entities with execution error Reply with quote

You didn't say what the error was, but...Are you sure your filter is working
properly and that it returns only lwp's? You also should have gotten a
compile error with objAcadEntity.Closed since that object type doesn't
support that method. You either need to dim the var as type AcadLWPolyline
or use the following structure if you don't know what type of ents are in
the ss:

Dim LWP As AcadLwPolyline
For Each objAcadEntity In objSSet
If TypeOf objAcadEntity Is AcadLwPolyline Then
Set objLWP = objAcadEntity
If objLWP.Closed Then

If you know that the ss will always contain only lwp's then:

Dim LWP As AcadLwPolyline
For Each objLWP In objSSet
If objLWP.Closed Then

--
----
Ed
----
Back to top
Nathan Taylor
Guest





Posted: Fri Jan 07, 2005 2:38 am    Post subject: Re: Auto Hatch entities with execution error Reply with quote

"You also should have gotten a compile error with objAcadEntity.Closed since that object type doesn't support that method."
If you declare an object as an AcadEntity it will support all methods that the object has. So the line will not cause an error but certainly as all is being selected are LWPolylines the variable should be declared as an AcadLWPolyline.
Regards - Nathan

Back to top
GerardK
Guest





Posted: Fri Jan 07, 2005 2:25 pm    Post subject: Re: Auto Hatch entities with execution error Reply with quote

Ed,

Thanks for your reply and help.
Your right.
It must be AcadLwPolyline.

But....................again the same error.

Command: -vbarun
Macro name: Module1.MakeHatchesFromLayer Execution error

(I also tryed "Unload me".)

In the .DVB I have several routines, forms and modules.
(works fine, without troubles)

I use module1 to test this VBa routine.
Nothing else is on module module1.

I use the following module to start this macro.

Function MyPullDownMenu()
Dim MyMenu As New ClsAcadMenu
GetAcadDrive

MyMenu.GroupName = "GK"
MyMenu.MakeMenuGroup GKMenuGroup

MyMenu.MenuName = "GK"
MyMenu.MakeMenuGroup GKMenu

MyMenu.MenuItemName = "Plot"
MyMenu.Macro = "-vbarun ModPlot.plot1 "
MyMenu.MakeMenuGroup GKMenuItem

MyMenu.MenuItemName = "RAL kleuren"
MyMenu.Macro = "-vbarun RAL.HatchColor "
MyMenu.MakeMenuGroup GKMenuItem

MyMenu.MenuItemName = "Opmerkingen toevoegen"
MyMenu.Macro = "-vbarun Tools.Notes "
MyMenu.MakeMenuGroup GKMenuItem

MyMenu.MenuItemName = "Test"
MyMenu.Macro = "-vbarun Module1.MakeHatchesFromLayer "
MyMenu.MakeMenuGroup GKMenuItem

ect.

MyMenu.ToolBarName = "GK"
MyMenu.MakeMenuGroup GKToolBar

MyMenu.BitmapName = PadBlocks & "Formulier.bmp"
MyMenu.MakeMenuGroup GKToolBarItem
End Function

(Menu works fine)


But, What do I wrong ??
Back to top
GerardK
Guest





Posted: Fri Jan 07, 2005 2:27 pm    Post subject: Re: Auto Hatch entities with execution error Reply with quote

Nathan,

Thanks for your reply and help.
Your right.
It must be AcadLwPolyline.

But....................again the same error.

Command: -vbarun
Macro name: Module1.MakeHatchesFromLayer Execution error

please see the reply I given to Ed.
Back to top
Ed Jobe
Guest





Posted: Fri Jan 07, 2005 9:09 pm    Post subject: Re: Auto Hatch entities with execution error Reply with quote

Execution Error only tells you that your macro failed to fully complete. If
its not breaking into the debugger like Robert mentioned, set a breakpoint
at the beginning of the sub and hit F5 to run the macro. It will stop at the
line where you added the breakpoint and you can step through the code one
line at a time and see exactly where it's failing. Hint: turn on the Debug
toolbar. The Step Into button will step into even other subs you call. The
Step Over button can pass it over if you know that sub is good.

--
----
Ed
----
"GerardK" <nospam@address.withheld> wrote in message
news:11762846.1105089976262.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
Ed,

Thanks for your reply and help.
Your right.
It must be AcadLwPolyline.

But....................again the same error.

Command: -vbarun
Macro name: Module1.MakeHatchesFromLayer Execution error

(I also tryed "Unload me".)

In the .DVB I have several routines, forms and modules.
(works fine, without troubles)

I use module1 to test this VBa routine.
Nothing else is on module module1.

I use the following module to start this macro.

Function MyPullDownMenu()
Dim MyMenu As New ClsAcadMenu
GetAcadDrive

MyMenu.GroupName = "GK"
MyMenu.MakeMenuGroup GKMenuGroup

MyMenu.MenuName = "GK"
MyMenu.MakeMenuGroup GKMenu

MyMenu.MenuItemName = "Plot"
MyMenu.Macro = "-vbarun ModPlot.plot1 "
MyMenu.MakeMenuGroup GKMenuItem

MyMenu.MenuItemName = "RAL kleuren"
MyMenu.Macro = "-vbarun RAL.HatchColor "
MyMenu.MakeMenuGroup GKMenuItem

MyMenu.MenuItemName = "Opmerkingen toevoegen"
MyMenu.Macro = "-vbarun Tools.Notes "
MyMenu.MakeMenuGroup GKMenuItem

MyMenu.MenuItemName = "Test"
MyMenu.Macro = "-vbarun Module1.MakeHatchesFromLayer "
MyMenu.MakeMenuGroup GKMenuItem

ect.

MyMenu.ToolBarName = "GK"
MyMenu.MakeMenuGroup GKToolBar

MyMenu.BitmapName = PadBlocks & "Formulier.bmp"
MyMenu.MakeMenuGroup GKToolBarItem
End Function

(Menu works fine)


But, What do I wrong ??
Back to top
GerardK
Guest





Posted: Sat Jan 08, 2005 2:57 am    Post subject: Re: Auto Hatch entities with execution error Reply with quote

Hello Ed,
And every one who's helping,

Some problems are solved. (I renamed the routine to test)
The reason for the Execution error was the first line.
Sub test(myLayerName As String)

After changing it to

Sub test()
Dim myLayerName As String

The Execution error was gone. Why ???? (It works)

Now running the program.

I can create in acad a closed polyline on two ways.
Point to point to point to endpoint or ... point to point to point and close.

In both cases there is a closed figure.

But.... This routine detect only closed polylines ONLY when the figures are closed by the letter "C" (To endpoint doesn't work!)
Why ?? Is close not close ??

After detection all the closed polylines, the system returns with error 424; object required.

Sub test()
Dim myLayerName As String
Dim arrOuterLoop(0) As AcadLWPolyline 'AcadEntity
Dim objAcadHatch As AcadHatch
Dim objSSet As AcadSelectionSet
Dim objAcadEntity As AcadEntity
Dim gpCode(0 To 1) As Integer
Dim gpValue(0 To 1) As Variant
Dim LWP As AcadLWPolyline

On Error GoTo ErrMakeHatchesFromLayer:

Set objSSet = ThisDrawing.SelectionSets.Add("SSet_MakeHatches")

gpCode(0) = 8: gpValue(0) = "0" 'myLayerName
gpCode(1) = 0: gpValue(1) = "LWPOLYLINE"
objSSet.Select acSelectionSetAll, , , gpCode, gpValue

For Each objLWP In objSSet
If objLWP.Closed Then
arrOuterLoop(0) = objAcadEntity
objAcadHatch = ThisDrawing.ModelSpace.AddHatch(acHatchPatternTypePreDefined, "SOLID", True)

objHatch.AppendOuterLoop objPline

objAcadHatch.AppendOuterLoop arrOuterLoop
objAcadHatch.Evaluate
objAcadHatch.Layer = "HATCH" 'myLayerName
End If
Next

ExitErrMakeHatchesFromLayer:
objSSet.Delete
Exit Sub

ErrMakeHatchesFromLayer:
MsgBox "Error : " & Err.Number & " - " & Err.Description

GoTo ExitErrMakeHatchesFromLayer:
End Sub

=================

Most of the time I changed the program (for try out) , I get the error "The named section set exists".
I'm restarting acad, undo the changes or modify the changes and this problem is solved (Til the next time).
Is there a more easy way to solve this, without restarting acad ??

Gerard
Back to top
Ed Jobe
Guest





Posted: Sat Jan 08, 2005 3:16 am    Post subject: Re: Auto Hatch entities with execution error Reply with quote

I don't have time at the moment to research your other problems, but I can
answer your first question.
Its because you can't directly run a sub that has arguments. They have to be
called by other subs.

--
----
Ed
----
"GerardK" <nospam@address.withheld> wrote in message
news:13236699.1105135101727.JavaMail.jive@jiveforum2.autodesk.com...
Quote:
Hello Ed,
And every one who's helping,

Some problems are solved. (I renamed the routine to test)
The reason for the Execution error was the first line.
Sub test(myLayerName As String)

After changing it to

Sub test()
Dim myLayerName As String

The Execution error was gone. Why ???? (It works)

Now running the program.

I can create in acad a closed polyline on two ways.
Point to point to point to endpoint or ... point to point to point and
close.

In both cases there is a closed figure.

But.... This routine detect only closed polylines ONLY when the figures
are closed by the letter "C" (To endpoint doesn't work!)
Why ?? Is close not close ??

After detection all the closed polylines, the system returns with error
424; object required.

Sub test()
Dim myLayerName As String
Dim arrOuterLoop(0) As AcadLWPolyline 'AcadEntity
Dim objAcadHatch As AcadHatch
Dim objSSet As AcadSelectionSet
Dim objAcadEntity As AcadEntity
Dim gpCode(0 To 1) As Integer
Dim gpValue(0 To 1) As Variant
Dim LWP As AcadLWPolyline

On Error GoTo ErrMakeHatchesFromLayer:

Set objSSet = ThisDrawing.SelectionSets.Add("SSet_MakeHatches")

gpCode(0) = 8: gpValue(0) = "0" 'myLayerName
gpCode(1) = 0: gpValue(1) = "LWPOLYLINE"
objSSet.Select acSelectionSetAll, , , gpCode, gpValue

For Each objLWP In objSSet
If objLWP.Closed Then
arrOuterLoop(0) = objAcadEntity
objAcadHatch =
ThisDrawing.ModelSpace.AddHatch(acHatchPatternTypePreDefined, "SOLID", True)

objHatch.AppendOuterLoop objPline

objAcadHatch.AppendOuterLoop arrOuterLoop
objAcadHatch.Evaluate
objAcadHatch.Layer = "HATCH" 'myLayerName
End If
Next

ExitErrMakeHatchesFromLayer:
objSSet.Delete
Exit Sub

ErrMakeHatchesFromLayer:
MsgBox "Error : " & Err.Number & " - " & Err.Description

GoTo ExitErrMakeHatchesFromLayer:
End Sub

=================

Most of the time I changed the program (for try out) , I get the error
"The named section set exists".
I'm restarting acad, undo the changes or modify the changes and this
problem is solved (Til the next time).
Is there a more easy way to solve this, without restarting acad ??

Gerard
Back to top
R. Robert Bell
Guest





Posted: Sat Jan 08, 2005 4:14 am    Post subject: Re: Auto Hatch entities with execution error Reply with quote

"GerardK" <nospam@address.withheld> wrote in message
news:13236699.1105135101727.JavaMail.jive@jiveforum2.autodesk.com...
....
But.... This routine detect only closed polylines ONLY when the figures are
closed by the letter "C" (To endpoint doesn't work!)
Why ?? Is close not close ??
....

Not from the perspective of the Closed property.
Back to top
GerardK
Guest





Posted: Sat Jan 08, 2005 9:09 pm    Post subject: Re: Auto Hatch entities with execution error Reply with quote

Quote:
...
But.... This routine detect only closed polylines ONLY when the figures are
closed by the letter "C" (To endpoint doesn't work!)
Why ?? Is close not close ??
...


Quote:
Not from the perspective of the Closed property.

To bad....................

Is there an other way to solve this problem, (or overrule) wich can make hatches from polylines wich are closed with the "close" command and the "to end" or to end coordinate ??

Gerard
Back to top
R. Robert Bell
Guest





Posted: Sat Jan 08, 2005 9:13 pm    Post subject: Re: Auto Hatch entities with execution error Reply with quote

Examine each LWPoly in your selection set and examine the beginning and
ending coordinates if the Closed property is False. If the coordinates
match, then hatch.

--
R. Robert Bell


"GerardK" <nospam@address.withheld> wrote in message
news:21427598.1105200593646.JavaMail.jive@jiveforum2.autodesk.com...
Quote:
...
But.... This routine detect only closed polylines ONLY when the figures are
closed by the letter "C" (To endpoint doesn't work!)
Why ?? Is close not close ??
...


Quote:
Not from the perspective of the Closed property.

To bad....................

Is there an other way to solve this problem, (or overrule) wich can make
hatches from polylines wich are closed with the "close" command and the "to
end" or to end coordinate ??

Gerard
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB