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

2011: iLogic, If view exists

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Rini11
2381 Views, 12 Replies

2011: iLogic, If view exists

Hi,

 

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?

 

Regards

Rikard

12 REPLIES 12
Message 2 of 13
MjDeck
in reply to: Rini11

There's other ways to do it, but this is probably the easiest:

 

Try
scale = ActiveSheet.View("VIEW1").Scale
Catch ex As ArgumentException
MessageBox.Show("VIEW1 not found", "iLogic Rule")
End Try

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.

 

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 13
Rini11
in reply to: MjDeck

Thanks Mike!!

 

I was on my way to ask if there where any "Try and Catch" in iLogic..

And you answered the question..

 

Thanks again..

 

Regards

Rikard

Message 4 of 13
guyh
in reply to: Rini11

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/yielding-to-ilogic-extracting-drawing.html

 

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...

 

Guy

 

PS any links or recommendations on the best way to learn how to use ilogic is much appreciated.

AutoCADM 2011 SP2
Inventor Pro 2011 SP2
Message 5 of 13
swordmaster
in reply to: guyh

Guy,

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.

Inventor 2010 Certified Professional
Message 6 of 13
MjDeck
in reply to: guyh

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

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 7 of 13
guyh
in reply to: Rini11

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!

 

Cheers,

Guy

AutoCADM 2011 SP2
Inventor Pro 2011 SP2
Message 8 of 13
guyh
in reply to: MjDeck







@MjDeck wrote:

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? 

 

Thanks

Guy

AutoCADM 2011 SP2
Inventor Pro 2011 SP2
Message 9 of 13
guyh
in reply to: guyh

Sorry, I've taken time to study it a bit more and realise this rule does it all!  Thanks a lot!

 

Cheers,

Guy

 

AutoCADM 2011 SP2
Inventor Pro 2011 SP2
Message 10 of 13
John_Col
in reply to: guyh

Hi,

 

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 😄

 

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 🙂

Message 11 of 13
MjDeck
in reply to: John_Col

Here is a rule (in the attached file AllViewScales.txt) that will put the scale information for all views on a sheet into a single iProperty.  There might be more than one line in the iProperty text, so you would need to allow extra space for the text on the drawing.  As provided, In Inventor 2012 the rule will create a custom iProperty named Sheet1ViewScales.  (In Inventor 2011, you will have to manually create this iProperty beforehand).  You can edit the rule (at the top in Sub Main) to change the name of this iProperty.  You can also change it to work on other sheets.


Mike Deck
Software Developer
Autodesk, Inc.

Message 12 of 13
John_Col
in reply to: MjDeck

Wow !

 

Awesome rule !

 

It's nearly too much !

 

Now I will think to improve my title block  🙂

 

I will try to modify this rule to have a more simple result for the moment as I don't have too much space in the title block.

 

My target is to have simply e.g. : 1:1   1:2   1:5   2:1   (according to all the views who are in sheet 1)

 

But your rule is very powerfull !!!! Thanks a lot !!!! For sure it's helps a lot !

Message 13 of 13
RoyWickrama_RWEI
in reply to: MjDeck

Thanks a lot. This is a good example of doing with a class. I got the idea and will continue more. 

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

Post to forums  

Autodesk Design & Make Report