External rule - Variable hides in an enclosing block - runs internally ok

External rule - Variable hides in an enclosing block - runs internally ok

andrew_canfield
Collaborator Collaborator
2,569 Views
10 Replies
Message 1 of 11

External rule - Variable hides in an enclosing block - runs internally ok

andrew_canfield
Collaborator
Collaborator

hello 

 

I've used copy & paste to move an iLogic rule which works locally to overwrite an external rule & now see this error:

Variable hides.JPG

 

How do I expose the variable?

 

Regards

 

Andrew

0 Likes
Accepted solutions (1)
2,570 Views
10 Replies
Replies (10)
Message 2 of 11

DRoam
Mentor
Mentor

Variables declared within block statements like If/Then, Try/Catch, For/Next, etc. have "block scope" and are only available within the code block in which they're declared. So if you try to use them outside the block, you'll get a compile error.

 

To make the variable available to your entire procedure, declare it outside the Try/Catch block, and then just set its value within the Catch block, like this:

 

Dim oVariable As VariableType
Try
     '...
Catch
     oVariable = ...
End Try

I'm surprised this worked at all in your local rule. It's difficult to determine why without seeing more of your code. But regardless, you should only declare a variable within a block if it's ONLY going to be used in that block.

0 Likes
Message 3 of 11

andrew_canfield
Collaborator
Collaborator

SyntaxEditor Code Snippet

Dim BE_PC as String  
Dim DisciplineCode As String 

I added the lines above at the start of the code but still see, 'BE_PC' hides & 'DisciplineCode' hides.

 

Thanks for looking.

 

Andrew

 

0 Likes
Message 4 of 11

andrew_canfield
Collaborator
Collaborator

I watch an AU tutorial which suggested bug fixing using visual studio:

i'll need to watch it again!

vb- properties.JPG

0 Likes
Message 5 of 11

DRoam
Mentor
Mentor

So did you get it working? If not, can you post your full code? (as text, not as a picture)

0 Likes
Message 6 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@andrew_canfield,

 

Actually, variable name (like BE_PC) and parameter name in drawing document are same. This is actual cause for errors.

 

Usually, all parameters in documents are defined with same variable name. For Example, If "BE_PC" parameter is defined in a document, "BE_PC" variable name is used in iLogic and can not be used again to another variable name.

 

In the attached rule, I can see all variable names are same as parameter names.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 11

andrew_canfield
Collaborator
Collaborator

Hello

I stripped the code back & the error message highlights a different line to what causes the problem:

SyntaxEditor Code Snippet

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oDrawParams As UserParameters = oDrawDoc.Parameters.UserParameters

'oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters

Try
'Change value of param
Parameter("BE_PC") = Parameter("BE_PC")
Catch
'Create Param as it doesn't exist
Dim BE_PC As UserParameter = oDrawParams.AddByValue("BE_PC" , "BE", UnitsTypeEnum.kTextUnits)
End Try 

the above works, it's adding the code below which causes the error:

 

SyntaxEditor Code Snippet

MultiValue.SetList("BE_PC", "BE", "PC")
BE_PC =  "BE"

So far:

Open a drawing, check if the required parameter is there - working

if it's not there create it - working

make the parameter multivalue - failing

 

the error is caused by lines 14 &  15 - not line 11:

14.JPG

 

Thanks again

 

Andrew

0 Likes
Message 8 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@andrew_canfield,

 

It would be better to test the error with document. So, please provide sample document to test the situation (Make sure that files are non confidential).

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 11

andrew_canfield
Collaborator
Collaborator

Please find sample.idw attached

0 Likes
Message 10 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@andrew_canfield ,

 

Still I strongly believe that error is due to line 12. Below iLogic code does not throw error. Just changed variable name for userparameter from BE_PC to BE_PC_1.

BE_PC = "BE"' deleted parameter


Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oDrawParams As UserParameters = oDrawDoc.Parameters.UserParameters

'oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters

Try
'Change value of param
Parameter("BE_PC") = Parameter("BE_PC")
Catch
'Create Param as it doesn't exist
Dim BE_PC_1 As UserParameter = oDrawParams.AddByValue("BE_PC" , "BE", UnitsTypeEnum.kTextUnits)
End Try 

MultiValue.SetList("BE_PC", "BE", "PC")
BE_PC =  "BE"

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 11

andrew_canfield
Collaborator
Collaborator

Thankyou - that works

0 Likes