Ilogic request - iproperty from 2nd model in sketch symbol

Ilogic request - iproperty from 2nd model in sketch symbol

-niels-
Mentor Mentor
691 Views
5 Replies
Message 1 of 6

Ilogic request - iproperty from 2nd model in sketch symbol

-niels-
Mentor
Mentor

Ok, just going to outright request this as i don't know how to find this using my usual copy/paste coding method and my lack of iLogic knowledge...

 

@Curtis_Waguespack, sorry for tagging you but i know you are really good at this stuff so maybe you can have a look?

 

This isn't that critical, but atm we have to remember to change this manually when we change/copy a drawing.

So, here's what i'm after:

 

We currently have a sketch symbol that prompts for a value of the 2nd model we place on a drawing.

This 2nd model is usually the mirrored version and the value we have to enter by hand is actually the iproperty "subject".

If we copy this drawing and the models to a new number, this iproperty value changes as well and we have to remember to update the sketch symbol.

 

If it is possible i would like to automate this by not using a manual entry, but the actual iproperty of the 2nd model.

My coding logic would be something like:

 

If <active drawing sheet> contains <part> or <assembly> with name like "####-##9####.*" then

    if <active drawing sheet> contains <sketch symbol>

       change <iproperty (subject)> in <sketch symbol> to <iproperty(subject)> of <part> or <assembly> with name like "####-##9####.*"

    else msgbox("prompt something")

else msgbox("prompt something")

This is probably a horrible piece of pseudo code, but i hope it gets my thoughts across.

 

Anyone care to help me out with this? if it's even possible?

Thank you in advance.

 

 


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

0 Likes
Accepted solutions (1)
692 Views
5 Replies
Replies (5)
Message 2 of 6

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi -niels-,

 

Thanks for the "outline" that was really helpful.

 

Here is what I came up with, note it's not well tested.

 

It looks at each view on the active sheet and does the like comparison to look at the file name of the model in that view.

 

Then it looks for a named symbol (just change that for your symbol name), and it assumes that symbol only has one textbox/prompt in it.

 

Then it updates the prompt in that symbol to use the summary iproperty from the model from that view.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'define symbol to look for
oSymbolName = "MySymbolName"

'get referene to active document (drawing)
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

For Each oView In oDrawDoc.ActiveSheet.DrawingViews
	'get model reference (path and name)
	oMDoc = IO.Path.GetFileName(ActiveSheet.View(oView.Name).ModelDocument.FullFileName)
	'split off just the name
	oSplit = Split(oMDoc,"\")
	'check if name is like format
	oNameCheck = oSplit(UBound(oSplit)) Like "####-##9####.*"	
	If oNameCheck = True Then
		'Iterate through each symbol in the active sheet
		For Each oSymbol In oDrawDoc.ActiveSheet.SketchedSymbols 
			'check against named symbol
			If oSymbol.Name = oSymbolName Then
				'get iproperty value
				oSummary = iProperties.Value(oMDoc, "Summary", "Subject")
				'set value of each textbox in symbole (assumes only one exists)
				For Each oTextBox In oSymbol.Definition.Sketch.TextBoxes
					Call oSymbol.SetPromptResultText(oTextBox, oSummary)
				Next
			End If
		Next	
	End If
Next

EESignature

0 Likes
Message 3 of 6

-niels-
Mentor
Mentor
Thanks Curtis, that looks like what i was thinking!
I'll try it out tomorrow when i'm back at work and let you know if i run into anything. Smiley Wink

Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

0 Likes
Message 4 of 6

-niels-
Mentor
Mentor

Hi Curtis,

 

I tried your code this morning and it works great!

 

I got an error at first, so i added a bunch of message boxes to see what was happening, turned out the symbol had 2 textboxes.

It was easy enough to filter out the one that needed to be changed, so i ended up with this code:

 

'define symbol to look for
oSymbolName = "Artikelnummer linksdeel"

'get referene to active document (drawing)
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

For Each oView In oDrawDoc.ActiveSheet.DrawingViews
	'get model reference (path and name)
	oMDoc = IO.Path.GetFileName(ActiveSheet.View(oView.Name).ModelDocument.FullFileName)
	'split off just the name
	oSplit = Split(oMDoc,"\")
	'check if name is like format
	oNameCheck = oSplit(UBound(oSplit)) Like "####-##9####.*"	
	If oNameCheck = True Then
	'MsgBox("linksdeel gevonden")
		'Iterate through each symbol in the active sheet
		For Each oSymbol In oDrawDoc.ActiveSheet.SketchedSymbols 
			'check against named symbol
			If oSymbol.Name = oSymbolName Then
			'MsgBox("sketch symbol gevonden")
				'get iproperty value
				oSummary = iProperties.Value(oMDoc, "Summary", "Subject")
				'MsgBox(oSummary)
				'set value of each textbox in symbole (assumes only one exists)
				'MsgBox(oSymbol.Definition.Sketch.TextBoxes.Count)
				For Each oTextBox In oSymbol.Definition.Sketch.TextBoxes
				'MsgBox(oTextBox.Text)
					If oTextBox.Text <> "+" Then
						Call oSymbol.SetPromptResultText(oTextBox, oSummary)
					End If
				Next
			End If
		Next	
	End If
Next

 

Many thanks for this, not sure how i can return the favor! Smiley Happy


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

Message 5 of 6

Curtis_Waguespack
Consultant
Consultant

@-niels- wrote:

... not sure how i can return the favor! Smiley Happy


Maybe I can pick a "theme" for a future Friday Pics thread? Nothing comes to mind at the moment though.

EESignature

Message 6 of 6

-niels-
Mentor
Mentor

Hi Curtis,

 

I wanted to thank you again for the code you provided.

After i showed it to my boss he found it to be really useful and wanted it to work with all our old files as well.

I looked into this and i found the only way to inject iLogic on an onSave event in existing files was with the help of an addin.

Because of that i decided to just add your code to our own addin instead.

 

Not that you'll need it, but i wanted to share the VB code with you:

 

 

Private Sub Linksdeelnummer()
            'define symbol to look for
            Dim oSymbolName = "Artikelnummer linksdeel"

            'get reference to active document (drawing)
            Dim oDrawDoc As DrawingDocument
            oDrawDoc = g_inventorApplication.ActiveDocument

            'Iterate through all drawing sheets
            For i = 1 To oDrawDoc.Sheets.Count
                'Set current sheet
                Dim oSheet As Sheet = oDrawDoc.Sheets.Item(i)

                'get name of first view for comparison
                Dim oFirstView As String
                oFirstView = oSheet.DrawingViews.Item(1).ReferencedFile.FullFileName
                Dim oSplitFirst = Split(oFirstView, "\")
                Dim oNameCompare = oSplitFirst(UBound(oSplitFirst))

                'Iterate through all drawing views
                For oView = 1 To oSheet.DrawingViews.Count
                    'get model reference (path and name)
                    Dim oMDoc = oSheet.DrawingViews.Item(oView).ReferencedFile.FullFileName
                    'split off just the name
                    Dim oSplit = Split(oMDoc, "\")

                    'check if name is like format
                    Dim oNameCheck = oSplit(UBound(oSplit)) Like "###?-##[7-9]####.*"
                    If oNameCheck = True And String.Compare(oSplit(UBound(oSplit)), oNameCompare) <> 0 Then

                        'Iterate through each symbol in the active sheet
                        For Each oSymbol In oSheet.SketchedSymbols
                            'check against named symbol
                            If oSymbol.Name = oSymbolName Then
                                'get iproperty value
                                Dim oSummary As Document = oSheet.DrawingViews.Item(oView).ReferencedFile.DocumentDescriptor.ReferencedDocument
                                Dim TekProp As PropertySet = oSummary.PropertySets.Item("Summary Information")
                                Dim SubjProp As String = TekProp.Item("Subject").Value

                                'Find the textbox to update
                                For Each oTextBox In oSymbol.Definition.Sketch.TextBoxes
                                    If oTextBox.Text <> "+" Then
                                        'compare values to see if update is necessary and ask user for confirmation
                                        If String.Compare(oSymbol.GetResultText(oTextBox), SubjProp) <> 0 Then
                                            If MsgBox("Artikelnummer linksdeel in titelblok bijwerken?" & vbCrLf _
                                                      & oSymbol.GetResultText(oTextBox) & " > " & SubjProp, vbYesNo + vbQuestion, oSheet.Name & ": " & oSplit(UBound(oSplit))) = vbYes Then
                                                Call oSymbol.SetPromptResultText(oTextBox, SubjProp)
                                            End If
                                        End If
                                    End If
                                Next
                            End If
                        Next
                    End If
                Next
            Next
        End Sub

 

As you can see, i made quite a few changes since we figured we had a little more conditions it had to adhere to.

Had some challenges getting everything working, so there might be some "flaws" in the way i programmed it but it is working.

 

I don't think i could've done this without your help, so if you want to choose a theme for a future Friday Pictures or want something rendered let me know.

Thanks again,

 


Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

0 Likes