Get active documents iProperties

Get active documents iProperties

meck
Collaborator Collaborator
1,235 Views
4 Replies
Message 1 of 5

Get active documents iProperties

meck
Collaborator
Collaborator

Hi All,

I have an iLogic external rule where I read the directory of the currently open part and then begin opening all .ipt files in the directory.

The problem is I need to read the iProperties of the newly opened part file, but it keeps reading the initial part file's properties. I've tried closing the initial file, but that creates all sorts of problems.

 

I've tried using the code below, but the revision number comes up blank.

 

Dim oiPartDoc As PartDocument
oiPartDoc = invApp.ActiveEditObject
oiPartDoc.Activate()
RevNo = oPropsets.Item("Design Tracking Properties").ItemByPropId(47).Value 'Not sure 47 is the correct value here????

 

Even if I could get the above code to work, I'd rather use the iLogic system snippets.

 

So what am I doing wrong with the code above AND is there some way to get the newly opened part to be read by using iProperties.Value("Project", "Revision Number")?

 

Thanks

Mike

 

 

 

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
1,236 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor

The issue with iLogic is that it is NOT cut out for accessing parts that are not directly referenced by your main document.

 

If you are opening from a directory and modifying parts, straight API is your best bet.

 

Clearly your understanding of programming is lacking, so I'd suggest reading up on vba/vb.net programming to get a BASIC understanding of how the languages work.

 

I'll highlight issues in your code below to point out where you are going wrong.

 

'The below line is fine and dandy; you are saying you are making a variable 
'named oiPartDoc that will hold a reference to a PartDocument type object
Dim oiPartDoc As PartDocument

'This line is interesting as you don't have invApp declared anywhere, and
'it's not one of the "Globally accessible" variables that can start a line without a previous declaration
' "ThisApplication" is one of these globally accessible variables, so we could use that instead and accomplish roughly
' the same thing.
'There could also be issues below, because You don't know FOR SURE that the active edit object will be a PartDocument,
' and seeing as you are stuffing it in the PartDocument containers, you're opened up for issues.
' The best solution is to do a test on the active edit object to see if it is a PartDocument BEFORE assigning it,
' Another option is to to make the variable you are assigning it to a "generic" container instead of a explicitly typed one oiPartDoc = invApp.ActiveEditObject

'The below line is fine as long as Activate is an available method/property of the TYPE of variable that oiPartDoc is. oiPartDoc.Activate()

'Again, like above, oPropsets isn't globally accessible, and you have nothing to assign oPropsets above, so this line is wrong.
'Further, you are mixing string indices and integer indices.... Stick with one or the other - strings for readability, or integers for the speed
' Don't use both as it's just sloppy. RevNo = oPropsets.Item("Design Tracking Properties").ItemByPropId(47).Value 'Not sure 47 is the correct value here???

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 5

MechMachineMan
Advisor
Advisor

What your solution should look like is this... but if you want to mass edit properties, just create a dummy assembly, drag the parts from the folder into the assembly, and edit them through the BOM....

 

Sub Main()
    Dim oDoc as Document
    oDoc = ThisApplication.ActiveDocument

    Dim oDocPath As String = System.IO.Path.GetDirectoryName(oDoc.FullFileName)
    oFiles = System.IO.Directory.GetFiles(oDocPath, "*.ipt", SearchOption.AllDirectories)

    For Each oFile in oFiles
       oSubDoc = ThisApplication.Documents.Open(oFile, True)
MsgBox("Look at me: " & vblf & oSubDoc.FullFileName) 'oSubDoc.PropertySets("Inventor Design Tracking Properties").Item("Description").Value = "TEST123" oSubDoc.Save oSubDoc.Close Next End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 5

meck
Collaborator
Collaborator

Having a bad day Justin? Insulting my programming ability seems a bit petty don't you think?

Here is the code I used with the connection to the Inventor application.

 

invApp = GetObject(, "Inventor.Application")
 Dim oiPartDoc As PartDocument
 
 oiPartDoc = invApp.ActiveEditObject
 oiPartDoc.Activate()

 

You code did not solve the issue. I get the same results.

 

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 5 of 5

MechMachineMan
Advisor
Advisor

Most people I see around who have an aptitude for coding are generally good at elaborating on issues and figuring out software.applications that they use (*ahem* Insert Code Boxes *ahem*). Sorry for my obviously incorrect assumption.

 

Did you try the code in the 2nd post that outlines a solution? If so, can you post back your modified version so we can investigate what the source of the issue might be?


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes