Alter model value on multiple drawing sheets

Alter model value on multiple drawing sheets

Anonymous
Not applicable
404 Views
3 Replies
Message 1 of 4

Alter model value on multiple drawing sheets

Anonymous
Not applicable

I am attempting to use iLogic to alter a custom property on a series of drawing sheets.  The sheets will each show a different model so the property can be different on each sheet.

 

The section of iLogic code that I am using is below.  It works on the first sheet in the series, but leaves the property on all other sheets blank.  Any suggestions?

 

 

For Each oSheet In oSheets
    oSheet.activate
    If ThisDoc.ModelDocument IsNot Nothing Then
    docFile = ThisDoc.ModelDocument
    Else
    MessageBox.Show("This drawing has no model reference", "iLogic")
    Return
    End If

    FNamePos = InStrRev(docFile.FullFileName, "\", -1)
    docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
    'define the property set
    customPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")
    
    'look for the custom property and add it if not found
    Try
    prop = customPropertySet.Item("MATERIAL")
    Catch
    customPropertySet.Add("", "MATERIAL")
    End Try

    matl = iProperties.Material(docFName)
    iProperties.Value(docFName, "Custom", "Material") = matl 'iProperties.Value(oModelName, "Custom", "Vendor")
Next

iLogicVb.UpdateWhenDone = True

 

0 Likes
Accepted solutions (1)
405 Views
3 Replies
Replies (3)
Message 2 of 4

HermJan.Otterman
Advisor
Advisor

Hello James,

 

 

your code referes always to the part on the first sheet.

you can see this if you print the name of the file on the sheet.

 

you have to use the part in the (first) view on the sheet.

 

I changed your code a bit.

 

I now will put a custom property in each part (what happens if that is an assembly?)

 

so if that property comes back on the sheet it should be there/changed.

 

but why put the material in an custom property?

there is a model property "material" that you use in a text, or put that in your title block...

 

the code:

 

 

osheets =  ThisDoc.Document.sheets
For Each oSheet In oSheets
    oSheet.activate
    Dim oView As drawingview = oSheet.drawingviews(1)
    Dim oRefDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.referencedDocument
'    If ThisDoc.ModelDocument IsNot Nothing Then
'    docFile = ThisDoc.ModelDocument
    MsgBox(oRefDoc.fullfilename)
'    MsgBox(docfile.FullFileName)
'    MsgBox(oSheet.Name)
'    Else
'    MessageBox.Show("This drawing has no model reference", "iLogic")
'    Return
'    End If

    FNamePos = InStrRev(oRefDoc.FullFileName, "\", -1)
    docFName = Right(oRefDoc.FullFileName, Len(oRefDoc.FullFileName) - FNamePos)
    'define the property set
    customPropertySet = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
    
    'look for the custom property and add it if not found
    Try
    prop = customPropertySet.Item("MATERIAL")
    Catch
    customPropertySet.Add("", "MATERIAL")
    End Try

    matl = iProperties.Material(docFName)
    iProperties.Value(docFName, "Custom", "Material") = matl 'iProperties.Value(oModelName, "Custom", "Vendor")
Next

iLogicVb.UpdateWhenDone = True

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 3 of 4

Owner2229
Advisor
Advisor
Accepted solution

Common Herm, you can do better. Using "For Each Sheet .Activate" is a waste of time. There's even already no need for it in your modification of the code, it's just slowing it down. You don't need to have the sheet active in order to access it's views, models etc. And the generation of each view (for each sheet) takes time (a lot in case of big assemblies).

Also I prefer accessing the iPros directly, but that's the matter of preference ofc.

 

Dim oSheets As Sheets = ThisDoc.Document.Sheets
For Each oSheet In oSheets
    Dim oView As DrawingView = oSheet.DrawingViews(1)
    Dim oRefDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	
    'Define the property sets and get the material property
    Dim oCustomSet As PropertySet = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
    Dim oDesignSet As PropertySet = oRefDoc.PropertySets.Item("Design Tracking Properties")
    Dim sMat As String = oDesignSet.Item("Material").Expression
	
    'Look for the custom property and add it if not found
    Dim oProp As Inventor.Property
    Try
        oProp = oCustomSet.Item("MATERIAL")
    Catch
        oProp = oCustomSet.Add("", "MATERIAL")
    End Try

    'Set the value of the custom iProperty
    oProp.Expression = sMat
Next

iLogicVb.UpdateWhenDone = True

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 4 of 4

Anonymous
Not applicable

@HermJan.Otterman wrote:

 

but why put the material in an custom property?

there is a model property "material" that you use in a text, or put that in your title block...

 

 


The reason for putting material in a custom property: my employer uses two material names - one for marketing purposes, and one for manufacturing purposes.  We use the Inventor model property for one, and a custom property for the other.  It's confusing and labor-intensive, which is the reason that I am trying to do this through iLogic.

 

0 Likes