Inventor General Discussion

Inventor General Discussion

Reply
Distinguished Contributor
Rini11
Posts: 139
Registered: ‎12-14-2004
Message 1 of 12 (908 Views)
Accepted Solution

2011: iLogic, If view exists

908 Views, 11 Replies
11-19-2010 12:33 AM

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

Employee
MjDeck
Posts: 959
Registered: ‎02-24-2009
Message 2 of 12 (887 Views)

Re: 2011: iLogic, If view exists

11-19-2010 10:04 AM 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
DLS - Mechanical Design
Autodesk, Inc.

Distinguished Contributor
Rini11
Posts: 139
Registered: ‎12-14-2004
Message 3 of 12 (880 Views)

Re: 2011: iLogic, If view exists

11-19-2010 11:06 AM 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

Distinguished Contributor
guyh
Posts: 369
Registered: ‎12-11-2007
Message 4 of 12 (650 Views)

Re: 2011: iLogic, If view exists

06-09-2011 08:31 AM 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
Distinguished Mentor
swordmaster
Posts: 539
Registered: ‎12-15-2008
Message 5 of 12 (645 Views)

Re: 2011: iLogic, If view exists

06-09-2011 09:30 AM 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
Employee
MjDeck
Posts: 959
Registered: ‎02-24-2009
Message 6 of 12 (636 Views)

Re: 2011: iLogic, If view exists

06-09-2011 10:15 AM 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
DLS - Mechanical Design
Autodesk, Inc.

Distinguished Contributor
guyh
Posts: 369
Registered: ‎12-11-2007
Message 7 of 12 (628 Views)

Re: 2011: iLogic, If view exists

06-09-2011 11:21 AM 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
Distinguished Contributor
guyh
Posts: 369
Registered: ‎12-11-2007
Message 8 of 12 (614 Views)

Re: 2011: iLogic, If view exists

06-10-2011 01:45 AM 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
Distinguished Contributor
guyh
Posts: 369
Registered: ‎12-11-2007
Message 9 of 12 (612 Views)

Re: 2011: iLogic, If view exists

06-10-2011 01:54 AM 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
Contributor
John_Col
Posts: 12
Registered: ‎03-13-2012
Message 10 of 12 (446 Views)

Re: 2011: iLogic, If view exists

03-13-2012 09:16 AM 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 :-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 :-)

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.