Open .iam in project folder ilogic?

Open .iam in project folder ilogic?

DeerSpotter
Collaborator Collaborator
2,225 Views
21 Replies
Message 1 of 22

Open .iam in project folder ilogic?

DeerSpotter
Collaborator
Collaborator

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!

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Accepted solutions (2)
2,226 Views
21 Replies
Replies (21)
Message 2 of 22

mrattray
Advisor
Advisor
I'm not sure if you can (or I just don't know how) to look at the project file data, however, I know we can get the file path of our current document. Would this work for you? Does the folder you're moving contain the document which this rule fires from?
Mike (not Matt) Rattray

0 Likes
Message 3 of 22

DeerSpotter
Collaborator
Collaborator

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.

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 4 of 22

mrattray
Advisor
Advisor
Accepted solution

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.

Mike (not Matt) Rattray

0 Likes
Message 5 of 22

DeerSpotter
Collaborator
Collaborator

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
Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 6 of 22

DeerSpotter
Collaborator
Collaborator

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...

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 7 of 22

rjay75
Collaborator
Collaborator

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.

0 Likes
Message 8 of 22

DeerSpotter
Collaborator
Collaborator

could you show me how to use that with?

ThisApplication.Documents.Open()
Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 9 of 22

rjay75
Collaborator
Collaborator

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)

 

0 Likes
Message 10 of 22

DeerSpotter
Collaborator
Collaborator

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.... 😞

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 11 of 22

rjay75
Collaborator
Collaborator
Accepted solution

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)

 

 

Message 12 of 22

DeerSpotter
Collaborator
Collaborator

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)
Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 13 of 22

DeerSpotter
Collaborator
Collaborator

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 🙂

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 14 of 22

rjay75
Collaborator
Collaborator

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()

 

Message 15 of 22

DeerSpotter
Collaborator
Collaborator

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. 

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 16 of 22

rjay75
Collaborator
Collaborator

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)

 

0 Likes
Message 17 of 22

DeerSpotter
Collaborator
Collaborator

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

 








Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 18 of 22

rjay75
Collaborator
Collaborator

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.

0 Likes
Message 19 of 22

DeerSpotter
Collaborator
Collaborator

1.PNG

2.PNG

 

3.PNG

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.

 

4.PNG

 
Gosh i hate doing Projects for Engineers that dont understand how to click the Return button up top. 😕

 

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
0 Likes
Message 20 of 22

rjay75
Collaborator
Collaborator

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.

0 Likes