I have a iLogic question about finding out if a View exits..
Lets say I have a drawing that I want to read the scale of a view.. All the snippets I have found is pointing to the name of the view like "VIEW1". But if I have deleted the first view I created it will give me an error..
So, is there ant possibility to check if the "VIEW1" exits without getting an error?
Solved! Go to Solution.
There's other ways to do it, but this is probably the easiest:
scale = ActiveSheet.View("VIEW1").Scale
Catch ex As ArgumentException
MessageBox.Show("VIEW1 not found", "iLogic Rule")
Note that if you use any other functions between the Try and Catch, they might throw a similar error and you won't be able to tell where the error came from. So it's best to put as little code as possible between the Try and Catch.
Hi, I am very new to using iLogic but already hooked and seeing the power it wields. I will look to learn as much as i can but for the moment I'm cutting my teeth on this subject.
I have used this code from here http://inventor-tales.blogspot.com/2010/08/yieldin
This creates my first rule.
'Forces update after rule runs iLogicVb.UpdateWhenDone = True 'Extracts scale from 'View 1' on drawing sheet' to a field named SCALE Dim strScale As String = ActiveSheet.View("VIEW1").ScaleString iProperties.Value("Custom", "SCALE1") = strScale
I have modified it very slightly to give me SCALE1 as I want 2 Scales listed in my title block.
I then create a 2nd rule for SCALE2
I tried to combine the code in one rule but get the error Local Variable "strScale" already declared in current block
I set up my event triggers and all works well if I have VIEW1 and VIEW2. If they do not exist then the rule returns an error. Is there a way to suppress this message or at least ask for the views rather than show this warning? It is then less alarming for somebody using the Template.
Thanks for any help...
PS any links or recommendations on the best way to learn how to use ilogic is much appreciated.
The reason for the error is that you already created the internal variable using
Dim strScale As String
you cannot do this twice so if you need to create more internal variables then these need a unique name like
Dim strScale2 As String
There is a recent post describing the code to test if a particular view is in a drawing,you can search for that it will help you out.
Here's a rule that will not give an error if either VIEW1 or VIEW2 or both don't exist.
For Each viewX As DrawingView In ActiveSheet.Sheet.DrawingViews If (viewX.Name = "VIEW1") Then iProperties.Value("Custom", "SCALE1") = viewX.ScaleString ElseIf (viewX.Name = "VIEW2") Then iProperties.Value("Custom", "SCALE2") = viewX.ScaleString End If Next
Thanks a lot guys. Really appreciate the help. Seeing just the start of what is possible I really want to learn more about this side and the API of Inventor. Time to get reading i guess!
Here's a rule that will not give an error if either VIEW1 or VIEW2 or both don't exist.For Each viewX As DrawingView In ActiveSheet.Sheet.DrawingViews If (viewX.Name = "VIEW1") Then iProperties.Value("Custom", "SCALE1") = viewX.ScaleString ElseIf (viewX.Name = "VIEW2") Then iProperties.Value("Custom", "SCALE2") = viewX.ScaleString End If Next
Hi Mike, sorry for the question as I am sure this is basic but can I just add this to my exisiting ilogic rules or do I need to create a new one?
This is a nice rule that we currently use, but I would like to improve it a little bit... but I'm a bit lost for the moment :-D
In fact, if we put one view 1 that is a 1:1 scale and another view which is 1:1, we will have two times 1:1 in our titleblock.
1 - Our target is to avoid redundancies(comparison of SCALE1 and SCALE2 with logic operators?)
2 - I would like to increase the number of possible views, it is possible to adapt the code to consider n Views?
Many thanks for your support :-)