iLogic - Comparing File Name to Part Number

iLogic - Comparing File Name to Part Number

douthett
Collaborator Collaborator
2,808 Views
11 Replies
Message 1 of 12

iLogic - Comparing File Name to Part Number

douthett
Collaborator
Collaborator

First off let me say that I'm a beginner when it comes to writing code, so I have a very basic idea of what I'm doing.  So when you point out my mistake, please explain why I did in very basic terms.

 

The code I'm writing is to compare the File Name and the Part Number.  If they match then it does nothing.  If they don't then a message will appear asking if the user want to fix the difference or leave it be.  If they want to leave it be then it creates a custom ipropertry that it will look for next time this code is ran.

 

I can get it all to run expect for the most important part and that is changing the part number so matches the file name.

 

Can someone point out my mistake and tell me in simple terms how to fix it?

 

 

oDoc = ThisDoc.FileName(False)

PartNumber = iProperties.Value("Project", "Part Number")

 

If PartNumber = oDoc

   Return

Else

   Try

       oProp = iProperties.Value("Custom", "NotFileName")

       Return

   Catch

       i = MessageBox.Show("Tree Name", "My iLogic Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)

             If i=MsgBoxResult.Yes Then

               oDoc = PartNumber

           ElseIf i=MsgBoxResult.No Then

               iProperties.Value("Custom", "NotFileName") = "No"

           EndIf

   End Try

 

End If

0 Likes
Accepted solutions (1)
2,809 Views
11 Replies
Replies (11)
Message 2 of 12

mslosar
Advisor
Advisor

I ran that on a blank file and when the dialog comes up and i choose NO, it creates the property in the custom tab.

 

Also, i'm thinking that oDoc=PartNumber is backwards and should be PartNumber=oDoc

You're setting the part number equal to the file name, correct? You can't see the filename equal to the part number.

0 Likes
Message 3 of 12

mslosar
Advisor
Advisor

Here:

 

SyntaxEditor Code Snippet

oDoc = ThisDoc.FileName(False)
PartNumber = iProperties.Value("Project", "Part Number")

MsgBox(oDoc)

If PartNumber = oDoc
    Return
Else
   Try
       oProp = iProperties.Value("Custom", "NotFileName")
       Return
   Catch
       i = MessageBox.Show("Tree Name", "My iLogic Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
             If i=MsgBoxResult.Yes Then
                 iProperties.Value("Project", "Part Number")=oDoc
               ElseIf i=MsgBoxResult.No Then
                   iProperties.Value("Custom", "NotFileName") = "No"
           End If
   End Try
 
End If
0 Likes
Message 4 of 12

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi Douthett,

 

Everything is fine except one that is, assigning file name(oDoc) to iProperties of Part Number.

 

Nothing wrong with the code. But, file name(oDoc) should be assigned to iProperties.Value("Project","PartNumber") in order to update in iProperties.

 

Please find the updated code in the following.

 

oDoc = ThisDoc.FileName(False)
PartNumber = iProperties.Value("Project", "Part Number")

If oDoc = PartNumber Then
	Return
Else
	Try 
		oProp = iProperties.Value("Custom", "NotFileName")
		Return
	Return
	Catch
		i = MessageBox.Show("Tree Name","My iLogic Dialog",MessageBoxButtons.YesNo,MessageBoxIcon.Hand ,MessageBoxDefaultButton.Button1)
		If i = MsgBoxResult.Yes Then
			iProperties.Value("Project", "Part Number") = oDoc
		ElseIf i = MsgBoxResult.No Then
			iProperties.Value("Custom", "NotFileName") = "No"
		End If
	End Try
End If

Please feel free to contact if there is any doubt.

 

If solves your problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 5 of 12

mslosar
Advisor
Advisor

Didn't I provide the same answer?

0 Likes
Message 6 of 12

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Mike,

 

In code, the following line having syntax error.

 

If oDoc = PartNumber

 

This line is not ending with "Then" in your code.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 12

patmang
Enthusiast
Enthusiast

May I ask how to apply such code?

 

 I could really use this as I am constantly manually changing this.

0 Likes
Message 8 of 12

MechMachineMan
Advisor
Advisor

Look through the Autodesk Help or Autodesk University for using iLogic....

 

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2014...

 

http://au.autodesk.com/au-online/classes-on-demand/class-catalog/2016/inventor-professional/sd17917#...

 

http://au.autodesk.com/au-online/classes-on-demand/class-catalog/2012/autodesk-inventor-products/ilo...

 

http://au.autodesk.com/au-online/classes-on-demand/class-catalog/2013/product-design-suite/ma1936#ch...

 

 

As time goes on I'm starting to think people are either become less capable of using google on their own, or more entitled. Not entirely sure which.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 12

patmang
Enthusiast
Enthusiast
"As time goes on I'm starting to think people are either become less capable of using google on their own, or more entitled. Not entirely sure which."As for above.....not nice...as for my question I was asking through an add-on using VB.net or through iLogic...GFY.
0 Likes
Message 10 of 12

MechMachineMan
Advisor
Advisor
I'm neither a mind reader nor paid to give you consultation. I'll remember
you are both a beggar and a chooser next time and not ensure you get timely
guidance.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 11 of 12

patmang
Enthusiast
Enthusiast

Thank You.

 

I appreciate that.

0 Likes
Message 12 of 12

patmang
Enthusiast
Enthusiast

Seriously, I do appreciate your help and thank you again for the links.

0 Likes