Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Model Custom Property to SketchSymbol definition

15 REPLIES 15
Reply
Message 1 of 16
robmatthews
1301 Views, 15 Replies

Model Custom Property to SketchSymbol definition

 

G'day.

 

How would i insert the "variable name" of a custom iProp to a sketched symbol definition (in an idw)?

 

I can plonk the value of the iProp in no worries, but to make it "live" is a bit beyond me...

 

 

Sub WeldNote()
On Error Resume Next
Dim oDoc As DrawingDocument
Dim SketchedSym As SketchedSymbolDefinition
Dim oNoteDef As SketchedSymbolDefinition
Dim oDefSketch As Sketch
Dim oTextbox As TextBox
Dim SNewText As String
Dim sNoteText As String
Dim oReffedDoc As Document
Dim lReffedWeldType As Long
'Err.Clear
If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then
    Set oDoc = ThisApplication.ActiveDocument
    Set oReffedDoc = oDoc.ReferencedDocuments(1)
    lReffedWeldType = oReffedDoc.PropertySets.Item("User Defined Properties").Item("WeldType").PropId
    If lReffedWeldType <> 0 Then
'Obviously this line below is the problem. This is only putting in the value, not a call to the parameter.
        SNewText = "NOTES:" & Chr(10) & "  1.  ALL DIMENSIONS ARE IN MILLIMETRES." & Chr(10) & _
            "  2.  ALL SHARP EDGES TO BE GROUND" & Chr(10) & "    SMOOTH AND FREE OF BURRS." & _
            Chr(10) & "  3. ALL WELDS " & oReffedDoc.PropertySets.Item("User Defined Properties").Item("WeldType").Expression & "  UNO"
        
        Set oNoteDef = oDoc.SketchedSymbolDefinitions.Item("HC Standard Note MM")
        If oNoteDef.Name <> "" Then
            oNoteDef.Edit oDefSketch
            Set oTextbox = oDefSketch.TextBoxes(1)
            oTextbox.Width = 10
            oTextbox.Text = SNewText ' sNoteText
            oNoteDef.ExitEdit True
            Set oTextbox = Nothing
        End If
    End If
    Set oNoteDef = Nothing
    Set oDoc = Nothing
End If
End Sub

 

=============================================
This is my signature, not part of my post.
15 REPLIES 15
Message 2 of 16
robmatthews
in reply to: robmatthews

Anyone know what I'm talking about? Anyone got any help for me?

 

Custom Prop.JPG

=============================================
This is my signature, not part of my post.
Message 3 of 16
robmatthews
in reply to: robmatthews

Is it unclear what I am attempting to do?

 

I want to invoke this macro, which finds the existing Sketched Symbol, and add the last line, which includes a reference to a custom iProp from the assy model.

 

I don't want to update the template, as this last line is only valid for particular types of assemblies (weldments, obviously).

 

Well anyway, thanks for looking.

=============================================
This is my signature, not part of my post.
Message 4 of 16
Qube-it
in reply to: robmatthews

Just to understand your intended workflow, let me see if I can explain it back to you.

 

On occasion you would want to append an additional line of text to all (or a selected set) of sketch symbols in a drawing file.  A portion of that line of text will be referencing the value of a custom iProperty in the current drawing file.

 

Does that sound right?

-Brian Hall-
Message 5 of 16
robmatthews
in reply to: Qube-it

Almost; the reference will be to a custom iProp in the referenced model rather than in the idw. Everything else is correct.

=============================================
This is my signature, not part of my post.
Message 6 of 16
Qube-it
in reply to: robmatthews

Ok.  Is the entire string in the code snippet you posted what you want to append (i.e. line 1,2,3 & 4), or is it just the value of the custom model property?

 

While you respond to that question think about this as an idea.  What if you actually did change the Sketch Symbol Definition inside your drawing template file to reference a custom Drawing iProperty?  By default, the value for that custom Drawing iProperty would be blank (which means it wouldn not show up in the sketch symbol), but when you actually wanted that to have the value of a custom model iProperty, you run a macro that pulls the value from the reference model into the custom Drawing iProperty.

 

Would something like that work?

 

Also, your code is referencing the iProperty "expression" and not the "value".  Just an observation.

-Brian Hall-
Message 7 of 16
robmatthews
in reply to: Qube-it

Hey Brian, thanks for looking at thise for me.

 

Firstly, I'm being a bit lazy with the string; rather than checking to see whether the extra text has already been appended, I'm just re-writing the entire text block; essentially overwriting the first 2 notes (over 4 lines) and adding the extra note (#3) at the end.

 

And yes, I remember now that i am getting .expression rather than .value; that was my last go-round trying to get the iProp itself in there, rather than a static value.

 

With regard to your second point, I did consider that early on, but the note is only valid for specific types of idws: welded assemblies.  And didn't really want to say "All welds <space space> UNO" on drawings of non-welded models. Unless we can make the entire line hidden until sugh time as the model has a valid value in that particular iProp...

 

Thanks for your time.

=============================================
This is my signature, not part of my post.
Message 8 of 16
Qube-it
in reply to: robmatthews

First of all let me say that I'm fairly weak with writing VBA so if there is something wrong with the syntax or structure of you code above, I probably missed it. I can say that I never use it and coming from a C# background it is quite different than what I'm used to syntatically.  That said, I can understand what someone else writes.

 

Here's how I would approach this (assuming I understand what you're after):

 

1) Manually create a custom iProperty inside the Drawing file called "AddedWeldNote" (or something to that effect).  It will default to being left blank.  This should be done inside your template drawing file.

 

2) Inside your Sketch Symbol Definition, manually open the text block and append a referenece to the "AddedWeldNote" iProperty you just created.  Since the value of that custom iProperty is null, nothing will show up when you finish editing.  This custom drawing iProperty reference will represent the entire line item including the referenced model iProperty.

 

3) Now, in your macro, get a reference to the "AddedWeldNote" custom drawing iProperty.

 

4) Get the value of the "WeldTypd" model iProperty that you want to refefernece.

 

5) Build up a string that represents the entire line (i.e. "3) All Welds are of type <"WeldType>  UNO") and assign that string to the value of the "AddedWeldNote" iProperty.

 

6) Finally, to keep the custom iProperty up to date listen for some events that will trigger this macro to run (like an OnSave event) which will have the effect of fetching the value of the "WeldType" model iProperty and refreshing the "AddedWeldNote" custom drawing iProperty.  This will only work once you fire the macro yourself.  If you never run the macro, then the subscription to the event will never happen and thus, the note will never be shown.

 

This a bit oversimplified but that's the jist of what I would go for.  It's a little more straight forward than modifying a Sketch Symbol Definition in my opinion.  

 

Did I completely miss what you're after or am I on the right track?

-Brian Hall-
Message 9 of 16
robmatthews
in reply to: Qube-it

Thanks for taking the time to look at and think about this Brian, I do appreciate it.

 

I understand where you're going with this, and I started to implement it, but there are two things that lead me to think that this is not the way to go, for me.

 

Firstly, it's not for an add-in (I haven't graduated to those yet...). This means that i can't really "listen" for any event.

Secondly, you're essentially suggesting I add another "layer" between the iProp and the text note (forget that it's in a sketched symbol for the time being).  This, in conjunction with the first issue, means that it's still going to be a static display of whatever the iProp was at time of initialisation (or refresh).

 

However, in a text field when a reference is added to an iProp, that reference will automatically update when the iProp is changed.

 

What you have done, though, is prompt another idea/aproach: change the idw template to refer to the iam iProp, and build the entire note string in the iam iProp. The user will only need to enter the weld type, and the rest of the note can be built around it.

 

Downside of this, is that if the user wants to edit the note manually in the idw (to add extra manufacturing conditions, say), then they will see the weldnote reference, which may not be valid. And if the weldnote is populated later, then the numbering of the note on the idw will gt out of whack, as there is not really a straight-forward way (there are ways, but long-winded) to see the current state of the idw note.

 

Do you follow me?

 

TL;DR version: your way wouldn't really work for me, but you've made me think of a way that would, but might not always be perfect.

 

Thanks Brian.

Rob.

=============================================
This is my signature, not part of my post.
Message 10 of 16
robmatthews
in reply to: robmatthews

Post script.

I guess my original question still stands:

 

Is there a way to programmatically add a live reference to a model iProp to a text field in an idw, per my post two in this thread?

=============================================
This is my signature, not part of my post.
Message 11 of 16
Qube-it
in reply to: robmatthews

There isn't a direct correlation between what you do in the user interface text editor and what you do with the API, so the "live" value isn't possible through the API like that.

 

To answer your question about getting a live update to the model iProperty, the short answer is "kind of".  The only way to keep the value of the model iProperty in sync is through some mechanism that checks the value of said model iProperty.  That mechanism is events.  For example when the user saves the drawing file, the event fires the function that you wrote to check the value of the model reference gets called (oversimplified).

 

Events aren't specific to Add-ins either.  They can also be used inside VBA Macros.  Another option is iLogic "Event Triggers" which are a list of commonly used events (like the BeforeSave and AfterSave events).  Those are accessible under the Manage tab on the iLogic panel and provide a very easy way to "listen" for certain common events and assign iLogic rules to fire in response to those events. 

 

Of course this would mean that you would write an iLogic rule instead of a macro but that would make it easier to migrate forward.  

 

Let me see if I can come up with something quick.

-Brian Hall-
Message 12 of 16
robmatthews
in reply to: Qube-it

Ok, cool. I haven't looked into events yet. I guess i just assumed that they were limited to add-ins.

 

Other information that might be pertinent: Inventor 2010. I don't think we have iLogic yet...?

 

(I see we are maintaining a 10 post difference between our post-counts... 🙂

=============================================
This is my signature, not part of my post.
Message 13 of 16
Qube-it
in reply to: robmatthews

10 post difference.  It's a binary sign of some kind. Smiley Happy

 

I'm positive that iLogic was at least available as an add-in for Inventor 2010.  I can't remember when it was officially added as part of the Inventor package though (2011 I think).

 

To get you down the right path for events I'll tell you to look inside the Inventor programming help.  Do a search for Document Events.  Double click on the topic that says "Event Detail Information".   That should give you a list of events of which you want to look at the 'OnSave" event.

 

I would also do a search for "User Interaction".  Double click on the topic that says "User Interaction".  That will give you a tutorial which covers events in the context of user interaction.  It's a different context but the same principles apply.  It goes into the VBA syntax a little as well.

 

Hopefully I've given you a direction.  Sorry I can't actually write something for you.  I have several things going on which are already not getting enough attention.

-Brian Hall-
Message 14 of 16
robmatthews
in reply to: Qube-it

No worries Brian, as I said, I appreciate the time.

 

I will investigate those avenues, too.

 

Thanks.

=============================================
This is my signature, not part of my post.
Message 15 of 16
Anonymous
in reply to: robmatthews

Hello Rob I have myself come accross a similar situation where I need to update a live custom property setting as the drawing saves. Unfortunately like yourself when a textbox is inserted manually with a custom property as a link it WILL update on save. I have written a macro that should effectively do the same thing except it only calls the value or expression of the custom property so it will not live update. How did you get around this problem or has anyone else had experiance with this? cheers

Message 16 of 16
robmatthews
in reply to: Anonymous

Hi there Reece.

 

I did not end up going to live variables in the idw.  I just read the current value of the variable, and insert that. If I change the value in the iam, I re-run the macro to update the text.

 

So, I'm sorry, but I did not solve this problem. Good luck, and feel free to post any solution you find here.

 

Rob.

=============================================
This is my signature, not part of my post.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report