- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I am looking for help to achieve the following.
On a network share there is a libraryfolder with subfolders filled with parts, from which we want to make copies into our working/project folder. The parts in the library are always like <code>_<6digitnumber>.ipt (ex: THYU_985236.ipt)
The copied parts in our projectfolder needs to stay unique, so after the partnumber there needs to be a counter added (ex: : THYU_985236_001.ipt, THYU_985236_002.ipt, THYU_985236_003.ipt)
The iLogic code needs to:
- ask for a 6 digit number.
- look for the part on the networkshare. (exit if it don’t exist)
- check if the file is already copied before (in the whole project folder .ipj & subfolders) and if so, modifies the COUNTER
- copy the part with the new filename to the folder where the active assembly resides
The copied parts need to be unique in the whole project, because they need custom properties which are unique tot the part (TAG Nr from P&ID)
Many Thanks!
kelly.young has edited your subject line for clarity: iLogic help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I am looking for help to achieve the following.
On a network share there is a libraryfolder with subfolders filled with parts, from which we want to make copies into our working/project folder. The parts in the library are always like <code>_<6digitnumber>.ipt (ex: THYU_985236.ipt)
The copied parts in our projectfolder needs to stay unique, so after the filename there needs to be a counter added (ex: : THYU_985236_001.ipt, THYU_985236_002.ipt, THYU_985236_003.ipt)
The iLogic code needs to:
- ask for a 6 digit number.
- look for the part on the networkshare. (exit if it don’t exist)
- check if the file is already copied before (in the whole project folder .ipj & subfolders) and if so, modifies the COUNTER
- copy the part with the new filename to the folder where the active assemby reisdes
The copied parts need to be unique in the whole project, because they need custom properties which are unique tot the part (TAG Nr from P&ID)
Is this doable in iLogic anyway?
Many Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous
Programming needs, issues, and questions for Inventor should be asked on the Inventor Customization forum for best results. I will have the moderator relocate your posting there to best suit your needs.
https://forums.autodesk.com/t5/inventor-customization/bd-p/120
Mark Lancaster
& Autodesk Services MarketPlace Provider
Autodesk Inventor Certified Professional & not an Autodesk Employee
Likes is much appreciated if the information I have shared is helpful to you and/or others
Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Anonymous,
As mentioned , you can search and ask programming questions of this type on the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
But here is a quick example that will do what you're looking for. I would create this as an external rule.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Imports System.IO
GetInput:
Six_Digit = InputBox("Enter 6 Digit number", "iLogic", )
If Six_Digit = "" Then
Return
Else If Len(Six_Digit) <> "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
Goto GetInput
End If
Dim oDoc As Document
Dim sFilename As String
oFolder = "C:\TEMP\Library\"
Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oFolder, _
"*.*", SearchOption.AllDirectories )
For Each oFilename As String In oFilenames
If oFilename.Contains(Six_Digit) Then
Dim oOptions As Inventor.NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
sFilename = oFilename
Exit For
End If
Next
If sFilename = "" Then
MessageBox.Show("No matching libary file found.", "iLogic")
Return
End If
iCounter = 0
oProjectfolder = "C:\TEMP\Work\"
Dim oProject_Filenames() As String
oProject_Filenames = System.IO.Directory.GetFiles(oProjectfolder, _
"*.*", SearchOption.AllDirectories )
'count existing project files
For Each oFilename As String In oProject_Filenames
If oFilename.Contains(Six_Digit) Then
iCounter = iCounter + 1
End If
Next
'increment counter
iCounter = iCounter + 1
'find the postion of the last backslash in the path
FNamePos = InStrRev(sFilename, "\", -1)
'get the file name with the file extension
oName = Right(sFilename, Len(sFilename) - FNamePos)
'get the file name (without extension)
ShortName = Left(oName, Len(oName) - 4)
'get extension
oExt = Right(oName, 4)
If iCounter < 10 Then
iCounter = "00" + CStr(iCounter)
ElseIf iCounter < 100 Then
iCounter ="0" + CStr(iCounter)
Else
iCounter = CStr(iCounter)
End If
oNewName = ShortName & "_" & iCounter
'save new document
oDoc.SaveAs(oProjectfolder & oNewName & oExt, True)
oDoc.Close
MessageBox.Show("New file created: " & vbLf & oProjectfolder & oNewName & oExt, "iLogic")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Wow, thank you very much. Did you wrote this just now, or did you have something simular on the shelve? I can only test this on monday @Anonymous, but thanks again.
Is it correct that i have to set the projectfolder in the code? So every new project, I have to modify this part of the code, right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Anonymous,
This was put together as an example just from other examples from the past.
As for changing the project, most likely it could determine the project folder from the some info in the current*.ipj file, or the current open file, or something along those lines... for example, you could just create this an an external rule, and then run it from an open assembly file that resides in the project folder, and the code would just look at the assembly file's location to determine the folder automatically.
Post back next week with more info, and i can likely help you make a quick update.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes, that folder automation ("project workspace folder" setting from the active ipj file) would be great.
One more thing; the freshly created unique part, should be inserted in the assembly, ready for constraining.
I definitly need to learn iLogic; never knew you could go so deep in programming inside inventor. Hope this works on monday! Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Anonymous
Here is a quick update that uses the parent folder of the current file (it expects an assembly).... as the "copy to" folder... and then this version places the component into the assembly.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Imports System.IO
GetInput:
Six_Digit = InputBox("Enter 6 Digit number", "iLogic", 985236 )
If Six_Digit = "" Then
Return
Else If Len(Six_Digit) <> "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
Goto GetInput
End If
Dim oDoc As Document
Dim sFilename As String
'hard code path
oLibrary_Folder = "C:\TEMP\Library\"
Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories )
For Each oFilename As String In oFilenames
If oFilename.Contains(Six_Digit) Then
Dim oOptions As Inventor.NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
sFilename = oFilename
Exit For
End If
Next
If sFilename = "" Then
MessageBox.Show("No matching libary file found.", "iLogic")
Return
End If
iCounter = 0
'path from current file
'oProjectfolder = ThisDoc.Path & "\"
'path from current project file ( *.ipj)
oProjectfolder = _
ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath & "\"
Dim oProject_Filenames() As String
oProject_Filenames = System.IO.Directory.GetFiles(oProjectfolder, _
"*.*", SearchOption.AllDirectories )
'count existing project files
For Each oFilename As String In oProject_Filenames
If oFilename.Contains(Six_Digit) Then
iCounter = iCounter + 1
End If
Next
'increment counter
iCounter = iCounter + 1
'find the postion of the last backslash in the path
FNamePos = InStrRev(sFilename, "\", -1)
'get the file name with the file extension
oName = Right(sFilename, Len(sFilename) - FNamePos)
'get the file name (without extension)
ShortName = Left(oName, Len(oName) - 4)
'get extension
oExt = Right(oName, 4)
If iCounter < 10 Then
iCounter = "00" + CStr(iCounter)
ElseIf iCounter < 100 Then
iCounter ="0" + CStr(iCounter)
Else
iCounter = CStr(iCounter)
End If
oNewName = ShortName & "_" & iCounter
oPathandName = oProjectfolder & oNewName & oExt
'save new document
oDoc.SaveAs(oPathandName, True)
oDoc.Close
'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)
'insert new occurence
Dim oOcc As ComponentOccurrence
oOcc = oAsmCompDef.Occurrences.Add( _
oPathandName, oMatrix)
oOcc.grounded = False
ThisDoc.Document.SelectSet.Select(oOcc)
']
'MessageBox.Show("New file created: " & vbLf & oPathandName, "iLogic")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is a great piece of code Curtis, simple and it does the job well. It could come in handy for everyone who don't like to work with Content Center, Library folder of which the parts are not allowed their iproperties to be updated.
It just copies parts from a folder, to your active workspace and keeps them unique. If you don't want them to be unique, just drag the same part from your model browser, so you got 2 instances of the same object.
The only thing that would be nice is to (1) show all origin and working planes and (2) activate the constrain dialog after the part is placed in the assembly. I think I can use iMates to simplify the constraining process. (3) hide all the origin and working planes to finnish.
And what if in time there are "Oldversion" folders, with filenames that contains the same 6 digits as the original? Or are "Oldversion" excluded in the search?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Did you write/test this in Inventor 2019? i am on 2018, and hoping that your code will still work in 2019.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Anonymous,
I ran this in Inventor 2017... but I would expect it to run fine with 2018 or 2019 also, but I don't have those versions on this computer at the current time.
I think there was an update with Inventor ilogic in 2019, but I forget the specifics at the moment.
Maybe we can ask @Mark.Lancaster to try this rule on 2019 and let us know if he sees any issue. Mark? ... if you have a spare minute. Thanks!
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous and @Curtis_Waguespack
It runs just give me a message no matching file found in C:\temp\library.
Mark Lancaster
& Autodesk Services MarketPlace Provider
Autodesk Inventor Certified Professional & not an Autodesk Employee
Likes is much appreciated if the information I have shared is helpful to you and/or others
Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If you have time, just place a part called "test_123456.ipt" in that folder, run the rule and enter 123456 in the dialogbox.
Thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Of course I am thankfull to Curtis for this great help so far. If possible I would like to keep the original partnumber from the library piece in the new created occurence (and not the new filename). Or if not possible on creation, modify the partnumber back to its original after placed in the assembly.
iProperties.Value("Part Number") = OriginalPartnumber
Many Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried a bit, but, why isn't he finding the document?
Error in rule: Rule4, in document: Assembly1.iam
iProperties:The document named "U:\temp\PTN_Part_Library\PIPE\PIPE_200011.ipt" was not found.
GetInput :
Six_Digit = InputBox("Enter 6 Digit number", "iLogic", 000000)
If Six_Digit = "" Then
Return
Else If Len(Six_Digit) <> "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
GoTo GetInput
End If
Dim oDoc As Document
Dim sFilename As String
'hard code path
oLibrary_Folder = "U:\temp\PTN_Part_Library\"
Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories)
For Each oFilename As String In oFilenames
If oFilename.Contains(Six_Digit) Then
Dim oOptions As Inventor.NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
sFilename = oFilename
Exit For
End If
Next
If sFilename = "" Then
MessageBox.Show("No matching libary file found.", "iLogic")
Return
End If
iCounter = 0
'trying to get the original partnumber
oOriginal_Partnumber = iProperties.Value(sFilename, "Project", "PartNumber")
MessageBox.Show(oOriginal_Partnumber)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Curtis (or anybody), this code is just great, but would it be possible to add a line of code so the the original partnumber from the library piece is transfered to the new created occurence (and not the filename)? many many thanks...
Imports System.IO
GetInput:
Six_Digit = InputBox("Enter 6 Digit number", "iLogic", 985236 )
If Six_Digit = "" Then
Return
Else If Len(Six_Digit) <> "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
Goto GetInput
End If
Dim oDoc As Document
Dim sFilename As String
'hard code path
oLibrary_Folder = "C:\TEMP\Library\"
Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories )
For Each oFilename As String In oFilenames
If oFilename.Contains(Six_Digit) Then
Dim oOptions As Inventor.NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
sFilename = oFilename
Exit For
End If
Next
If sFilename = "" Then
MessageBox.Show("No matching libary file found.", "iLogic")
Return
End If
iCounter = 0
'path from current file
'oProjectfolder = ThisDoc.Path & "\"
'path from current project file ( *.ipj)
oProjectfolder = _
ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath & "\"
Dim oProject_Filenames() As String
oProject_Filenames = System.IO.Directory.GetFiles(oProjectfolder, _
"*.*", SearchOption.AllDirectories )
'count existing project files
For Each oFilename As String In oProject_Filenames
If oFilename.Contains(Six_Digit) Then
iCounter = iCounter + 1
End If
Next
'increment counter
iCounter = iCounter + 1
'find the postion of the last backslash in the path
FNamePos = InStrRev(sFilename, "\", -1)
'get the file name with the file extension
oName = Right(sFilename, Len(sFilename) - FNamePos)
'get the file name (without extension)
ShortName = Left(oName, Len(oName) - 4)
'get extension
oExt = Right(oName, 4)
If iCounter < 10 Then
iCounter = "00" + CStr(iCounter)
ElseIf iCounter < 100 Then
iCounter ="0" + CStr(iCounter)
Else
iCounter = CStr(iCounter)
End If
oNewName = ShortName & "_" & iCounter
oPathandName = oProjectfolder & oNewName & oExt
'save new document
oDoc.SaveAs(oPathandName, True)
oDoc.Close
'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)
'insert new occurence
Dim oOcc As ComponentOccurrence
oOcc = oAsmCompDef.Occurrences.Add( _
oPathandName, oMatrix)
oOcc.grounded = False
ThisDoc.Document.SelectSet.Select(oOcc)
']
'MessageBox.Show("New file created: " & vbLf & oPathandName, "iLogic")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The parts are always inserted at the same point 50,50,50, I suppose...
Would you be so kind to have a look and tell me what I should change to insert the new part near my mouse pointer?
Many Thanks, Johan