Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API equivalent to Try Catch End Try

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Mark_Wigan
2678 Views, 3 Replies

API equivalent to Try Catch End Try

hi, i wonder if someone can assist me please?

 

  as a small part of a larger API proceedure i am writing, i am trying to check if a specific property (actually a colour in this case) exists in a part document prior to changing an existing property to one that i "hope" is already in the part document.

 

having done some searching and testing today, i see that iLogic uses a nice function : Try Catch End Try, however this does not work in the inventor API at least as far as i currently know how to program it.

 

i have used other functions in different languages but i need something in the inventor API to carry out the same sort of a quick check first, if not found then i will make it, if found then i will carry out the change type of action.

 

failing the opportunity to use a nice checking function like the iLogic "try catch", the idea i have is that i could transverse the entire property set ie; RenderStyles.Item("my special colour") to search for what i am interested in, and check via using for each / next loop and if i find what i "hope" is there, then i can easily go to the execution of what i want to change.

with my limited experience though, i suspect that if i do not find the property i want to use, then i still need to flag this to be able to handle the situation, thus leading me back to my initial challenge.

 

alternatives:

 

a) error handling; i have not done much in the way of error handling or know how to find out the error type to handle it, or if that is the sensible way to handle the situation.

 

b) null; i have no experience using "null" checking either yet. i will research this next.

 

i hope someone can give me some tips on this. i suspect what i need is probably available and will save me a bit of messing around doing it the hard way.

 

-many thanks as always.

best regards,
- Mark

(Kudo or Tag if helpful - in case it also helps others)

PDSU 2020 Windows 10, 64bit.

3 REPLIES 3
Message 2 of 4
xiaodong_liang
in reply to: Mark_Wigan

Hi,

 

One of your comments confused me: "Try Catch End Try, however this does not work in the inventor API at least as far as i currently know how to program it."

 

From where or which case, you draw a conclusion Try/Catch does not work?  Try/Catch is frequently used with Inventor API program. And we often use it to check if an item exists in a collection, if catched, we will add the new item. 

 

error handling is a usage with VB/VBA. It is OK you like to live with it, but I still suggest Try/Catch if you are using .NET or iLogic.

Message 3 of 4
Mark_Wigan
in reply to: Mark_Wigan

hi and thanks for your reply.

 

i am not an expert in inventor API but when i saw "try catch" in an ilogic post i was hopeful, however to date i am unable to get it to work in inventor API.

 

i searched the help and api support and could not locate any information.

 

if you use it then i am very happy to hear this as i think it will help my programming. i wonder if you have any example for me to try to get it to work, eg for example transversing the render styles within a part, to check if a colour exists, if not then i will creat the colour, prior to assigning it to a object variable.

best regards,
- Mark

(Kudo or Tag if helpful - in case it also helps others)

PDSU 2020 Windows 10, 64bit.

Message 4 of 4
xiaodong_liang
in reply to: Mark_Wigan

I am curious how you searched the API reference. With the keywords “try catch”, I can get some pages contain try/catch. Even one page (VBA to .Net Quick Reference) lists the difference between VB and .NET, one of which is “Error object/method/properties in VB ; Try Catch statement with exception handling  in .NET.

 

In addition, in SDK samples, there are lot of lines using try/catch.

 

As to your requirement, I have not an exact sample at this moment, but probably this post could be a start for you.

 

http://adndevblog.typepad.com/manufacturing/2012/07/setting-the-color-of-a-part-in-conjunction-with-...

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

Post to forums  

Autodesk Design & Make Report