Macro Error

Macro Error

Anonymous
Not applicable
384 Views
6 Replies
Message 1 of 7

Macro Error

Anonymous
Not applicable
Hello,
We have a macro that works on some dwgs but not others. Other macros we use work fine. We did have an update to a dwg that we use as a template, but of course the udate should have been transparent (layout page setup and simple text). What could be the cause?
0 Likes
385 Views
6 Replies
Replies (6)
Message 2 of 7

arcticad
Advisor
Advisor
I would check for references.
There may be a program that is missing on one computer and not the other, or they may be different versions.
Step through the code and see where it stops.
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 7

Anonymous
Not applicable
My crystal ball rolled off the desk the other
day and broke, so I can't help you.

The problem you vaguely describe can have
thousands of possible causes, most of them
being specific to your code.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5420105@discussion.autodesk.com...
Hello,
We have a macro that works on some dwgs but not others. Other macros we use work fine. We did have an update to a dwg that we use as a template, but of course the udate should have been transparent (layout page setup and simple text). What could be the cause?
0 Likes
Message 4 of 7

Ed__Jobe
Mentor
Mentor
Some of the "vague" terms: "works", "doesn't work". If you are not sure how to accurately describe the problem, show your code.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 7

Anonymous
Not applicable
What I mean is: We have three macros. Sitting at my station, with two dwgs open, two of the macros work fine in both dwgs. One of the macros works fine in an older dwg, but returns "Execution Error" in the other dwg. The macro is supposed to count the number of block instances, populate a schedule and prompt the user for an insertion point.

Sub PanelSchedule()


' This routine inserts a panel schedule into a 1/4-scale drawing file
' This routine counts the panels in a drawing

Dim ss1 As AcadSelectionSet
Set ss1 = ssAdd("ssName")
Dim codes(0) As Integer
Dim values(0)

Dim straightCount As Integer
Dim leftCount As Integer
Dim rightCount As Integer
Dim doubleCount As Integer
Dim hdrCount As Integer
Dim hdlCount As Integer


codes(0) = 2 '2 is filter number for blocknames

'Initialize counts to zero
straightCount = 0: leftCount = 0: rightCount = 0: doubleCount = 0: hdrCount = 0: hdlCount = 0

'Straights
ss1.Clear
values(0) = "Straight"
ss1.Select acSelectionSetAll, , , codes, values
straightCount = ss1.Count

ss1.Clear

values(0) = "Straight Through Panel"
ss1.Select acSelectionSetAll, , , codes, values
straightCount = straightCount + ss1.Count



'Lefts
ss1.Clear
values(0) = "Left"
ss1.Select acSelectionSetAll, , , codes, values
leftCount = ss1.Count

ss1.Clear

values(0) = "Left Turn Panel"
ss1.Select acSelectionSetAll, , , codes, values
leftCount = leftCount + ss1.Count

'Rights
ss1.Clear
values(0) = "Right"
ss1.Select acSelectionSetAll, , , codes, values
rightCount = ss1.Count

ss1.Clear

values(0) = "Right Turn Panel"
ss1.Select acSelectionSetAll, , , codes, values
rightCount = rightCount + ss1.Count

'Full Doubles
ss1.Clear
values(0) = "Double"
ss1.Select acSelectionSetAll, , , codes, values
doubleCount = ss1.Count

ss1.Clear

values(0) = "Double Turn Panel"
ss1.Select acSelectionSetAll, , , codes, values
doubleCount = doubleCount + ss1.Count

'HD Lefts
ss1.Clear
values(0) = "Half Double - Left Turn"
ss1.Select acSelectionSetAll, , , codes, values
hdlCount = ss1.Count

ss1.Clear

values(0) = "HD-L"
ss1.Select acSelectionSetAll, , , codes, values
hdlCount = hdlCount + ss1.Count

'HD Rights
ss1.Clear
values(0) = "Half Double - Right Panel"
ss1.Select acSelectionSetAll, , , codes, values
hdrCount = ss1.Count

ss1.Clear

values(0) = "HD-R"
ss1.Select acSelectionSetAll, , , codes, values
hdrCount = hdrCount + ss1.Count

doubleCount = doubleCount + (IIf((hdlCount > hdrCount), hdlCount, hdrCount))

' Insert the block
Dim pSchedule As AcadBlockReference
Set pSchedule = ThisDrawing.ModelSpace.InsertBlock(ThisDrawing.Utility.GetPoint(, "Insertion point: "), "PanelCntBlk.dwg", 1#, 1#, 1#, 0)

' Get the attributes for the block reference
Dim varAttributes As Variant
varAttributes = pSchedule.GetAttributes

varAttributes(0).TextString = straightCount
varAttributes(1).TextString = leftCount
varAttributes(2).TextString = rightCount
varAttributes(3).TextString = doubleCount

' Move the attribute tags and values into a string to be displayed in a Msgbox
' Dim strAttributes As String
' Dim I As Integer
' For I = LBound(varAttributes) To UBound(varAttributes)
' strAttributes = strAttributes & " Tag: " & varAttributes(I).TagString & _
' " Value: " & varAttributes(I).TextString & " "
' Next
' MsgBox "The attributes for " & pSchedule.Name & " are: " & strAttributes, , "GetAttributes Example"


End Sub

Public Function ssAdd(strName As String) _
As AcadSelectionSet
On Error Resume Next
ThisDrawing.SelectionSets(strName).Delete
Set ssAdd = ThisDrawing.SelectionSets.Add(strName)
End Function
0 Likes
Message 6 of 7

Ed__Jobe
Mentor
Mentor
Nothing is jumping out at me, other than you don't have any error handling, hence the "execution error". Put a breakpoint at the first line of code and run the macro in the problem dwg. Then step though the code until it errors. Its probably something like a "type mismatch" error or a variable is not getting set.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 7

Anonymous
Not applicable
Thank you.
0 Likes