issue pushing iproperties to other part

issue pushing iproperties to other part

peter.roman
Advocate Advocate
506 Views
5 Replies
Message 1 of 6

issue pushing iproperties to other part

peter.roman
Advocate
Advocate

I've got a part W2400 that pushes iproperties to another part W2400_str by running the following ilogic code (that I found and adapted from these forums) with a "before save document" trigger.

The problem is I consistently get an error on 1st save and then if works on 2nd save (and when used in a larger assembly it disrupts the saving of the other unrelated parts on 1st save).

 

Any ideas on how to fix this or a better way to get the end result?

 

Dim str_part As String = ThisDoc.PathAndFileName(False) & "_str.ipt"
new_desc = iProperties.Value("Project", "Description")
new_part = iProperties.Value("Project", "Part Number")

Dim oDoc As Inventor.Document = ThisApplication.Documents.Open(str_part, False)
Dim oPropsets As PropertySets = oDoc.PropertySets
Dim oProject As PropertySet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")
oProject("Description").Expression = new_desc
oProject("Part Number").Expression = new_part
oDoc.Save()
oDoc.Close()

 

error 1.PNGerror 2.PNG

 

0 Likes
507 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

I noticed that the two models are similar, but definately different.  One straight and one bent.

Is one part created before the other? Are either of these parts created by code durring this same 'before save' event?  Why would their 'before save' event be triggered from an assembly?  Have they not both been saved off as individual files before being used in the assembly?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

Perhaps if you put a couple more checks in there to help 'dummy proof' it like this, it may help with the errors.

By the way, I also changed the long PropID looking string to the name of the Property, to help simplify it.

In my experience, those PropID type strings, can change from release to release, leaving you wandering "why does it not work anymore?".

 

Dim str_part As String = ThisDoc.PathAndFileName(False) & "_str.ipt"
'MsgBox("str_part = " & str_part)
If System.IO.File.Exists(str_part) = False Then
	MsgBox("The File " & str_part & vbNewLine &
	" doesn't exist yet.",vbExclamation,"FILE DOESN'T EXIST!")
	Return
Else
	new_desc = iProperties.Value("Project", "Description")
	new_part = iProperties.Value("Project", "Part Number")

	Dim oOpen As Boolean = False
	Dim oODocs As Documents = ThisApplication.Documents
	For Each oODoc As Document In oODocs
		If oODoc.FullFileName = str_part Then
			oODoc.Activate
			oOpen = True
		End If
	Next
	If oOpen = False Then
		Dim oDoc As Inventor.Document = ThisApplication.Documents.Open(str_part, False)
		Dim oPropsets As PropertySets = oDoc.PropertySets
		Dim oProject As PropertySet = oPropsets.Item("Project")
		oProject("Description").Value = new_desc
		oProject("Part Number").Value = new_part
		oDoc.Save()
		oDoc.Close()
	End If
End If

 

I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.

 

Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.

  • MessageBox, InputBox, and InputListBox Size & Format Options Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

peter.roman
Advocate
Advocate

Hi,

I've yet to give your code a go but just to answer your questions:

 

They both pre-exist. When the bent part is edited it calculates its length and then the straight part picks that up through parameter link (that part works fine).

Neither are created by code.

The workflow is that the bent part is in the assembly (that I have open), I'll edit the bent part, maybe some other unrelated parts (in the assembly), maybe multiple separate bent parts (in the assembly), then I'll save (either the bent part or the assembly which then prompts to save the bent part as well).

The straight part is also in the assembly so it gets picked up by pack and go, design assistant etc.

The before save trigger is so that if there is any chance that the relevant iproperties were changed in the bent part, those changes get pushed over to the straight part. (the straight part gets used in the drawing)

 

The error still happens even if the bent part is the only thing I have open (so unrelated to being in an assembly).

 

UPDATE:

I've tried your code but get the following error

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

Also when I try my code with the PropID string changed with "Project" I get a different error

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))

 

I'm not sure how to get more useful debugging info.

 

I also noticed your changed .Expression with .Value, does that do anything?

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

I couldn't test the code, so apparently I posted it too quickly and made a mistake.

I didn't define the Property Set correctly, before trying to access the Properties within.

Try this version.

 

Dim str_part As String = ThisDoc.PathAndFileName(False) & "_str.ipt"
'MsgBox("str_part = " & str_part)
If System.IO.File.Exists(str_part) = False Then
	MsgBox("The File " & str_part & vbNewLine &
	" doesn't exist yet.",vbExclamation,"FILE DOESN'T EXIST!")
	Return
Else
	new_desc = iProperties.Value("Project", "Description")
	new_part = iProperties.Value("Project", "Part Number")

	Dim oOpen As Boolean = False
	Dim oODocs As Documents = ThisApplication.Documents
	For Each oODoc As Document In oODocs
		If oODoc.FullFileName = str_part Then
			oODoc.Activate
			oOpen = True
		End If
	Next
	If oOpen = False Then
		Dim oDoc As Inventor.Document = ThisApplication.Documents.Open(str_part, False)
		Dim oPropSet As PropertySet = oDoc.PropertySets.Item("Design Tracking Properties")
		oPropSet.Item("Part Number").Expression = new_part
		oPropSet.Item("Description").Expression = new_desc
		oDoc.Save()
		oDoc.Close()
	End If
End If

 

No. There is little difference between Value & Expression.

The diffenence doesn't seem to be very well documented in the Online Help area.

An Expression is always going to be in the form of a String, while a Value can be a String, Double, Date, or Boolean, type data.  This is why the Value route is usually the more popular one to use.

I believe using Expression is useful if you want to include 'live linked iProperty values' within your String.  This can be a very helpfull for automation purposes, if you're familiar with how to do it.

For example, in a new part file, go into your iProperties dialog / Summary tab, and manually type whatever you want within the Title text box.  Then go do the Project tab, and within the Description text box type: "=<Title>", without the quotes.  When you click Apply, it instantly changed to say whatever is in your Title area, and you will now see an Fx symbol next to that property's text box, meaning it knows it is displaying a linked Expression.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

peter.roman
Advocate
Advocate

The thing is both files always exist so the first check doesn't really do anything

If System.IO.File.Exists(str_part) = False Then

 

I think the issue lies with

oDoc.Save()

I don't seem to get the error if I remove this and just save manually.

 

I've updated my code as below, including some of your additions.

It checks if the straight part is open already (in the context of an assembly) and if not it opens it "visibly" (in it's own window; if it's already open I don't open a new window for it).

The iproperties get pushed to it.

Then I can save the assembly / now open part or if I try to close it I will now get a prompt to save (which I wouldn't get on closing without doing it this way).

 

Dim str_part As String = ThisDoc.PathAndFileName(False) & "_str.ipt"
new_desc = iProperties.Value("Project", "Description")
new_part = iProperties.Value("Project", "Part Number")

Dim oOpen As Boolean = False
Dim oODocs As Documents = ThisApplication.Documents
For Each oODoc As Document In oODocs
	If oODoc.FullFileName = str_part Then
		oOpen = True
		Exit For
	End If
Next

Dim oDoc As Inventor.Document = ThisApplication.Documents.Open(str_part, Not oOpen)
Dim oPropSet As PropertySet = oDoc.PropertySets.Item("Design Tracking Properties")
oPropSet.Item("Description").Expression = new_desc
oPropSet.Item("Part Number").Expression = new_part

 

0 Likes