AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using VBA to find commands?

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
504 Views, 9 Replies

Using VBA to find commands?

Hello all,

Here's my situation. I have a bunch of drawings in a project folder. Some of the drawings have revision clouds in them, some don't. I'm trying to build a program that asks the user for the project folder, than goes through each drawing one by one, and if it finds a revision cloud, ask the user if he wants to delete it or leave it. Whatever they choose, the program will continue onto the next drawing until it processes them all.

However, here's the problem. Whether it was a lack of foresight, or something else, the revision clouds weren't added on their own unique layer. I've noticed that revision clouds are polylines, but so are other lines in the drawing itself. The only unique identifier I can find is that the clouds themselves were made using the "REVCLOUD" command.

My question is: Is there some syntax in VBA that searches and identifies that this object was made with REVCLOUD, or is that not even possible. And I should add my experience with VBA has been limited thus far.

Thanks!
- David
9 REPLIES 9
Message 2 of 10
rhesusminus
in reply to: Anonymous

Hi David.

There is no way to find out what command was used to create an entity in a
drawing.
I created this littet function that might help you tho':

Private Function IsRevCloud(ByRef lwpLine As AcadLWPolyline) As Boolean

Dim lngCounter As Long

IsRevCloud = False

' Polyline must be closed, to be considered as RevCloud
If lwpLine.Closed = False Then
Exit Function
End If

' There must be morgfe than "X" segments in the polyline to be
considered a polyline (6 in this example)
If (UBound(lwpLine.Coordinates) + 1) / 2 < 6 Then
Exit Function
End If

' All segments must have a "bulge" to be considered a RevCloud
For lngCounter = 0 To (UBound(lwpLine.Coordinates) - 1) / 2
If lwpLine.GetBulge(lngCounter) = 0 Then
Exit Function
End If
Next

' All tests checked. Probably a RevCloud.
IsRevCloud = True

End Function




THL

"DTran" wrote in message news:5976888@discussion.autodesk.com...
> Hello all,
>
> Here's my situation. I have a bunch of drawings in a project folder.
> Some of the drawings have revision clouds in them, some don't. I'm trying
> to build a program that asks the user for the project folder, than goes
> through each drawing one by one, and if it finds a revision cloud, ask the
> user if he wants to delete it or leave it. Whatever they choose, the
> program will continue onto the next drawing until it processes them all.
>
> However, here's the problem. Whether it was a lack of foresight, or
> something else, the revision clouds weren't added on their own unique
> layer. I've noticed that revision clouds are polylines, but so are other
> lines in the drawing itself. The only unique identifier I can find is
> that the clouds themselves were made using the "REVCLOUD" command.
>
> My question is: Is there some syntax in VBA that searches and identifies
> that this object was made with REVCLOUD, or is that not even possible.
> And I should add my experience with VBA has been limited thus far.
>
> Thanks!
> - David

Trond Hasse Lie
AutoCAD Electrical and EPLAN expert
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 3 of 10
Anonymous
in reply to: Anonymous

Hi Rhesus. Your idea looks very promising, and I was trying to modify it slightly to meet my need.

Here's what I have so far:

Dim acadObj As AcadObject
Dim acadPoly As AcadLWPolyline

For Each acadObj In ThisDrawing.ModelSpace
If TypeOf acadObj Is AcadLWPolyline Then
Set acadPoly = acadObj
IsRevCloud (acadPoly)
If IsRevCloud = True Then
checkPLines = True
Set MyPLine = acadObj
End If
End If
Next

Here's the problem. When it goes through the "If IsRevCloud = True" I get an error message: Argument not optional.

So then I tried making a global variable within the function you wrote up called "checkCloud" as boolean and had it equal false where IsRevCloud = false, and = true when IsRevCloud equal true.

IsRevCloud (acadPoly)
If checkCloud = True Then <- changed
checkPLines = True
Set MyPLine = acadObj

Now it hangs at the "IsRevCloud (acadPoly) with the error: object doesn't support this property or method

If you could help me understand why it doesn't work, it'd be much appreciated.
Message 4 of 10
Anonymous
in reply to: Anonymous

Nevermind that last post. I figured out that I need to place "Call" in front of IsRevCloud (acadPoly).

The problem now is that it doesn't seem to be finding the rev clouds in the drawing...
Message 5 of 10
Anonymous
in reply to: Anonymous

For some reason, checking to see if the rev cloud has a bulge always turns out 0, which is why it never recognized the clouds. Once I commented that section out, it worked like a charm. Thanks again for your help!

- David
Message 6 of 10
rhesusminus
in reply to: Anonymous

There is also something else wrong with your code (if it still looks like
this)
Try this:

Dim acadObj As AcadObject
Dim acadPoly As AcadLWPolyline

For Each acadObj In ThisDrawing.ModelSpace
If TypeOf acadObj Is AcadLWPolyline Then
Set acadPoly = acadObj
If IsRevCloud (acadPoly) = True Then
checkPLines = True
Set MyPLine = acadObj
End If
End If
Next



The bulge check should be appropriate, but i could have a look if you'd send
me a drawing of yours.

THL

Trond Hasse Lie
AutoCAD Electrical and EPLAN expert
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 7 of 10
Anonymous
in reply to: Anonymous

Sure thing.
Message 8 of 10
rhesusminus
in reply to: Anonymous

try this one:
Private Function IsRevCloud(ByRef lwpLine As AcadLWPolyline) As Boolean

Dim lngCounter As Long

IsRevCloud = False

' Polyline must be closed, to be considered as RevCloud
If lwpLine.Closed = False Then
Exit Function
End If

' There must be more than "X" segments in the polyline to beconsidered a
polyline (6 in this example)
If (UBound(lwpLine.Coordinates) + 1) / 2 < 6 Then
Exit Function
End If

' All segments must have a "bulge" to be considered a RevCloud
For lngCounter = 0 To (UBound(lwpLine.Coordinates) - 3) / 2
If lwpLine.GetBulge(lngCounter) = 0 Then
Exit Function
End If
Next

' All tests checked. Probably a RevCloud.
IsRevCloud = True

End Function



The first and the last point in the polylines were on the same coordinate,
hence no bulge.

THL

Trond Hasse Lie
AutoCAD Electrical and EPLAN expert
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 9 of 10
Anonymous
in reply to: Anonymous

Well, that was an easy fix - changing the 1 to a 3.
It works, by the way.
Thanks again.
Message 10 of 10
Anonymous
in reply to: rhesusminus

Sorry to ressurect an old thread but I would like to utilize this method for checking if rev clouds exist within an entire project but I am not a programmer.  I can get around in the VBAIDE environment but don't know what code I need.  Can anyone tell me how to use the code within this thread to check for all rev clouds?

 

THanks 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost