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
Solved! Go to Solution.
Solved by waynehelley. Go to Solution.
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
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!
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,
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
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)
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.
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,
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.
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.
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.
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.
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.
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
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
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.
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.
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.