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: 

ilogic code to check a drawing file name matches the part present in the drawing

24 REPLIES 24
SOLVED
Reply
Message 1 of 25
waynehelley
6558 Views, 24 Replies

ilogic code to check a drawing file name matches the part present in the drawing

Hi there,

 

at my company we use part numbers as file names for everything. for example, part number 09090P00100000, will be saved as 09090P00100000.ipt and will have a drawing saved as 09090P00100000.idw.

 

Within the drawing template file, i want to set up an ilogic rule that will check that the part present in the drawing corresponds to the file name of the drawing. This rule will run after saving and will just display a warning if the file names do not correspond.

 

I just need some code that will get the file name of the part displayed in the drawing.  Note that we use iparts so the code must get the member file name and not the factory file name.

 

Dim oDrawingDoc As DrawingDocument

oDrawingDoc = ThisApplication.ActiveDocument  

Dim oSheet As Sheet   

oSheet = oDrawingDoc.ActiveSheet

'get document file name

docname=ThisDoc.FileName(False) 'without extension

instancefilename=??

If docname = instancefilename

Exit Sub

Else

MessageBox.Show("The file name does not match the part number", "Drawing File Name Check", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)

End If

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
24 REPLIES 24
Message 2 of 25
waynehelley
in reply to: waynehelley

I have just realised I can just get the Part Number instead. Problem solved!

 

Dim oDrawingDoc As DrawingDocument

oDrawingDoc = ThisApplication.ActiveDocument  

Dim oSheet As Sheet   

oSheet = oDrawingDoc.ActiveSheet

'get document file name

docname=ThisDoc.FileName(False) 'without extension

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

If docname = partno

Exit Sub

Else

MessageBox.Show("The file name does not match the part number of the instance present in the drawing views.", "Drawing File Name Check", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)

End If

 

Does anyone have any ideas how to improve on this? I think I know how to set the code to replace model reference with the appropriate file, but I would need to include '&"ipt"' or '&"iam"'.  I'm not sure if I know how to write it so that it would work with both parts and assemblies  Smiley Frustrated

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 3 of 25
waynehelley
in reply to: waynehelley

Oh no, using the part number doesn't work as the part number doesn't always correspond to the instance present in the drawing.

 

Back to my first problem!

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 4 of 25
waynehelley
in reply to: waynehelley

Got there in the end. Any suggestions for improvements would be much appreciated.

 

'exit if there are no drawing views

If (ThisDrawing.ModelDocument Is Nothing) Then Return

'get document file name docname=ThisDoc.FileName(False) 'without extension

'get model file name modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)  

'Remove extension modelName = Left(modelName, Len(modelName) - 4)   

If docname = modelName

Exit Sub

Else

MessageBox.Show("This drawing's file name does not match the part number of the instance present in the drawing views.", "Drawing File Name Check", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)

End If

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 5 of 25

Wayne,

 

 Try this:

 

doc = ThisDoc.FileName(False)
modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
cnt = Len(modelName)
name = Left(modelName, (cnt - 4))
var = String.Compare(doc, name, True)

If var <> 0 Then
MessageBox.Show("The filename does not match the Part Number", "Drawing File Name Check", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
End If

 

You can then define an Event Trigger to run the rule upon saving the file.

 

If you have any questions, shoot me an email at:

 

thomas.fitzgerald@autodesk.com

 

 

Thomas Fitzgerald

Technical Consultant

Autodesk Consulting

 

 

Thomas Fitzgerald

Principal Implementation Consultant
Message 6 of 25

Thanks Thomas,

 

do you know a line of code that will find out what type of drawing view the drawing contains. (it will be either .ipt, iam. or .ipn)

 

once I know that, I can make it so that the message box gives the option to replace model referance with the appropriate model (assuming it exists in the same folder as the currently referanced model)

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 7 of 25

vname = IO.Path.GetFileName(ActiveSheet.View("VIEW1").ModelDocument.FullFileName)
ext = Right(vname, 3)

This will get you the extension of a file used for a particular view.
Thomas Fitzgerald

Principal Implementation Consultant
Message 8 of 25

Thanks again Thomas,

 

i have managed to take my code one step further and give the user the option to replace the referanced model with one corresponding to the drawing's file name.

 

I just have the problem that my drawings views will not update automatically! do you know a code to make this happen?

 

i have tried;

 

oDrawingDoc.Update
oDrawingDoc.Update2
oSheet.Update

 

but haven't had any luck. I will attach my code

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 9 of 25

Wayne,

 

  You can use:

 

InventorVb.DocumentUpdate()

 

This will update the Active Document.

 

You can also use:

 

iLogicVb.UpdateWhenDone = True

 

This will update the Active Document and any children files associated with the Active Document.

Thomas Fitzgerald

Principal Implementation Consultant
Message 10 of 25
waynefisher
in reply to: waynehelley

Thanks for posting this. It helped me get what I need!!

Message 11 of 25

Hello Thomas,

I know you are very good at writing rules on Inventor, that is why i need your help on this task.

I have two folders one with parts, the other with assemblies. I trying to write a code for a part to show all the assemblies that use this specific part. 

Message 12 of 25

Unfortunately, there isn't a way to accomplish that with iLogic code or API code.  Unlike the assembly and drawing files, the individual component files do not hold the dependency information, short of derived components.  This is why it is important to use a Data Management software like Vault.  It uses a database to store the relationship information so that a user can understand where a particular component might be used throughout all assemblies.  Without that, from a part level, there is no other way of understanding file dependencies.  

 

Thomas Fitzgerald

Principal Implementation Consultant
Message 13 of 25

I cannot seem to get the error message when running the rule.  I have interntionally copied design unchecking the rename part number to file name box. Just doesn't seem to send the message when I run the rule. Any suggestions. People here are not checking the box, and wrong parts are getting released due to the General Arrangement still saying the copied part info from the I Properties. So I also need this type of double check rule very badly. 

Message 14 of 25
t_fransman
in reply to: waynehelley

Re: ilogic code to check a drawing file name matches the part present in the dra

I cannot seem to get the error message when running the rule.  I have interntionally copied design unchecking the rename part number to file name box. Just doesn't seem to send the message when I run the rule. Any suggestions. People here are not checking the box, and wrong parts are getting released due to the General Arrangement still saying the copied part info from the I Properties. So I also need this type of double check rule very badly. 

Message 15 of 25
waynehelley
in reply to: t_fransman

Hi there,

 

What version on the code are you attempting to run?  The above code from Thomas.fizgerald seems to work perfectly for me.

 

Are you running the code as an internal iLogic rule?

 

You mention 'copied part info from the I Properties'.  This script is looking at file names by the way and doesn't look at the iProperties at all.

 

Wayne

 
Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 16 of 25
waynehelley
in reply to: t_fransman

If you are wanting to run the rule within a drawing (i.e. an idw or dwg) to check if the drawing file name matches the 'Part Number' of the component in the drawing, this is what you need...

 

doc = ThisDoc.FileName(False)
name = IO.Path.GetFileName(ThisDrawing.ModelDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value)

var = String.Compare(doc, name, True)

If var <> 0 Then
MessageBox.Show("The filename does not match the Part Number", "Drawing File Name Check", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
End If

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 17 of 25
t_fransman
in reply to: waynehelley

Sorry let me try to be more clear. I am trying to find a check that will identify if the file name does or does not match the Iproperties Part number field because people here are forgetting to check the box at the top of the "Copy Design" with vault. This leads to the part still having the copied parts part number therefore the person working on an arrangement of parts is releasing the wring part.  I have tried several of the code snippets in this thread, none seem to fire the message. My file name is incorrect and does not match the Part number, because I have purposefully un-checked the box during my test "copy design". Thanks in advance please advise which code works for this if any. Sorry for the confusion.

Message 18 of 25
t_fransman
in reply to: t_fransman

I have tried the snippets as Rules, and external rules. To no effect.

Message 19 of 25
t_fransman
in reply to: waynehelley

Thanks Wayne that does seem to work now. I may need more info or have some more specifics, but that's a huge step forward. 

Message 20 of 25

How is the rule being triggered?  The code may be right, but if you are not triggering or running the rule at the right time, you may not see the desired result.  If you can provide a screen capture video of your process, that might be helpful.

Thomas Fitzgerald

Principal Implementation Consultant

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

Post to forums  

Autodesk Design & Make Report