instead of this can i actually have it look at current project folder?
'these links will need to be updated for current physical location everytime folder is moved or renamed. Public Sub Main() If Component.IsActive("DETAIL B 26310C:1") Then ThisApplication.Documents.Open("G:\FEA\Baseline\shell outer _ 26310c rev - (Ilogic)\DETAIL B 26310C.iam", True) End If If Component.IsActive("DETAIL B 26310C REV1:1") Then ThisApplication.Documents.Open("G:\FEA\Baseline\shell outer _ 26310c rev - (Ilogic)\DETAIL B 26310C REV1.iam", True) End If If Component.IsActive("DETAIL B 26310C REV2:1") Then ThisApplication.Documents.Open("G:\FEA\Baseline\shell outer _ 26310c rev - (Ilogic)\DETAIL B 26310C REV2.iam", True) End If End Sub
Any help would help out alot.... thanks!
Solved! Go to Solution.
Solved by rjay75. Go to Solution.
Solved by mrattray. Go to Solution.
Yes Getting the File Path of the Current Assembly would be good enough. Thing is that those assemblies are actually in a subassembly.
Could we just somehow eliminate the G:/ instead just have last folder location? or something similar... whatever would work.
You can use this to get the path of the current document:
ThisDoc.Path
Or, while I was double checkling that function, I noticed this:
ThisDoc.WorkspacePath()
One of these should work for you.
trying to solve this equation im still getting errors would you be able to help me?
you can see that by specifing full path it opens it, but by trying to do the code trick it always errors out. even if i use
ThisDoc.WorkspacePath()
Any ideas?
If Component.IsActive("DETAIL B 26310C:1") Then
'ThisApplication.Documents.Open("G:\FEA\Baseline\shell outer _ 26310c rev - (Ilogic)\DETAIL B 26310C.iam", True)
ThisApplication.Documents.Open(ThisDoc.Path("DETAIL B 26310C.iam"), True)
'ThisApplication.Documents.Open(Component.IsActive(MakePath("DETAIL B 26310C.iam")))
End If
i also went as far as this to try to open the document...:/ same error
'define the active document oDoc = ThisDoc.Document 'create a file dialog box Dim oFileDlg As inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) 'check file type and set dialog filter If oDoc.DocumentType = kPartDocumentObject Then oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt" Else If oDoc.DocumentType = kAssemblyDocumentObject Then oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam" Else If oDoc.DocumentType = kDrawingDocumentObject Then oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw" End If 'Set the directory To open the dialog at oFileDlg.InitialDirectory = ThisDoc.WorkspacePath() If Component.IsActive("DETAIL B 26310C:1") Then 'set the file name string to use in the input box oFileDlg.FileName = ("DETAIL B 26310C.iam") ThisApplication.Documents.Open(oFileDlg.InitialDirectory(oFileDlg.FileName)) End If
I'm completely lost...
The WorkspacePath, InitialDirectory, Path are all string variables, not functions. To append them to your file name you need to do this.
Dim fullName As String fullName = ThisDoc.WorkspacePath & "\" & "DETAIL B 26310C:1"
Also if you have any more directories after the path you have to include them as well.
could you show me how to use that with?
ThisApplication.Documents.Open()
Assuming you have the file in the root directory of the workspace path:
Dim fullName As String fullName = ThisDoc.WorkspacePath & "\" & "DETAIL B 26310C.iam" ThisApplication.Documents.Open(fullName)
why doesnt this work? Grrrrr
Public Sub Main() Dim fullName1 As String fullName1 = ThisDoc.WorkspacePath & "\" & "DETAIL B 26310C:1" If Component.IsActive("DETAIL B 26310C:1") Then ThisApplication.Documents.Open(fullname1, True) End If End Sub
welp.... 😞
If the location of the assembly and the components are in the same folder then you can do this.
Dim fullName1 As String fullName1 = ThisDoc.Path & "\" & "DETAIL B 26310C.iam" ThisApplication.Documents.Open(fullName1, True)
ThisDoc.Path is the location of the file running the rule.
ThisDoc.WorkspacePath is the root workspace folder.
If you want to see what they are create a rule and add this:
MessageBox.Show("Doc Path: " & ThisDoc.Path & VbCrLf & "Workspace Path: " & ThisDoc.WorkspacePath)
This will help you to see which path you want to use. You a have to add any missing sub directories between the path and the file name.
So if your ThisDoc.WorkspacePath equals "G:\FEA\Baseline" and then it would be
Dim fullName as String fullName = ThisDoc.WorkspacePath & "\shell outer _ 26310c rev - (Ilogic)\DETAIL B 26310C.iam"
ThisApplicationDocuments.Open(fullName, True)
If your ThisDoc.Path equals "G:\FEA\Baseline\shell outer _ 26310c rev - (Ilogic)"
Dim fullName as String fullName = ThisDoc.Path & "\DETAIL B 26310C.iam" ThisApplicationDocuments.Open(fullName, True)
this part worked for me! You just saved me hours of research!
Thanks!
Dim fullName as String fullName = ThisDoc.Path & "\DETAIL B 26310C.iam" ThisApplicationDocuments.Open(fullName, True)
Okay now to compound on this resolved issue. (i feel this thread is going to be viewed by a great many).
What kind of ILogic Code can i use to instead of opening something up; but editing it in place?
Any ideas?
Please let me know 🙂
You can activate the edit of a component from iLogic. But only one component in an assembly at a time.
'Start The edit of a component
Component.InventorComponent("DETAIL B 26310C REV2:1").Edit()
'End the edit of a component
Component.InventorComponent("DETAIL B 26310C REV2:1").ExitEdit()
exit edit is not working.... is there any more of a generic type of exit edit?
EditExit () seems to work slightly, but it cant find component.
Are you calling it from a rule in the assembly or component.
To use it that way it needs to be called from the assembly. (And I missed a parameter for it too.)
'End the edit of a component Component.InventorComponent("DETAIL B 26310C REV2:1").ExitEdit(kExitToPrevious)
This Right here Works:
Public Sub Main() If Component.IsActive("DETAIL B 26310C:1") Then 'Start The edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").Edit() End If If Component.IsActive("DETAIL B 26310C REV1:1") Then 'Start The edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").Edit() End If If Component.IsActive("DETAIL B 26310C REV2:1") Then 'Start The edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").Edit() End If End Sub
But when i create a rule in the Subassembly that it is editing like so, it cant find component. But if i create the rule in the original assembly and run it through a form it gives me a hresult:
Public Sub Main() If Component.IsActive("DETAIL B 26310C:1") Then 'End the edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").ExitEdit(kExitToPrevious) End If If Component.IsActive("DETAIL B 26310C REV1:1") Then 'End the edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").ExitEdit(kExitToPrevious) End If If Component.IsActive("DETAIL B 26310C REV2:1") Then 'End the edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").ExitEdit(kExitToPrevious) End If End Sub
The reason it doesn't work while it's editing a component is the component by name only exists in the assembly. Whenever a component function is run the function searches the file that owns the rule for that component name. So if the file is not an assembly and if it is but doesn't internally have a component of that name the rule won't work.
Doing it from the assembly is the correct way.
One note if you want only one of these to be able to edited when the rule is run, modify your IF blocks. Theorectically if two of your components are active it can try and edit both at the same time.
Public Sub Main() If Component.IsActive("DETAIL B 26310C:1") Then 'Start The edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").Edit() Else If Component.IsActive("DETAIL B 26310C REV1:1") Then 'Start The edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").Edit() Else If Component.IsActive("DETAIL B 26310C REV2:1") Then 'Start The edit of a component Component.InventorComponent("shell outer _ 26310c rev -:1").Edit() End If End Sub
This will do only one of the options testing them in order.
the above images: this is running the rules from the main baseline.iam
the image below is running the rule from the actual component that is being edited.
Gosh i hate doing Projects for Engineers that dont understand how to click the Return button up top. 😕
If you running it from the baseline assembly you need to use MakePath to get to the interior sub components.
Component.IsActive(MakePath("shell outer _ 26310c rev -:1", "DETAIL B 26310C:1"))
Everything would have to be traversed through there subassemblies from the baseline assembly.