Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Properties + math/text-formula

Status
Not open for further replies.

Jwouters

Mechanical
Feb 19, 2009
24
Hello all,

Working with SW2009 (4.1)

I'm trying to get some math/text funtions in the properties of a part.

What I'm trying to achieve is the following:
-Name / Text / $PRP:"SW-File Name"
-Name2 / Text / $PRP:"SW-File Name" - "SomeText"

Example:
The file name is: "172-Cardoor-SomeText"
Name2 would then have to be "172-Cardoor"

Is there some way to achieve such thing? I know how this could be done with something like Excel or something ... but SW ? Excel from what I've heard :p

-Grz J.
 
Replies continue below

Recommended for you

You are right. It is not particularly possible.

There are a couple of possible ways to work around it, though. You could use Excel functions inside a design table to evaluate text and drive properties. However, the values would only update if you open the design table.

Another way would be to set up a template that contains a macro feature. That would not be quite as simple or straightforward as a DT (and a very daunting task for a beginner), but the macro feature would update the custom property with every rebuild.

-handleman, CSWP (The new, easy test)
 
Hmm, ye thought so allready.

I've done some VB about 8 years ago. Looking at some existing macro like Lenny's makes me dizzy :D. Too bad, I'll go find for some other solution I guess. Ty anyway :)

-J
 
Just out of curiousity, is the difficult part the writing of the VB macro or the integration in a template?

A dirty work-around could be opening and closing the design-table (record it with macro-recorder). Then u have ur macro... my knowledge ends there... now how to integrate it in a template... ?
 
Handleman,

I read this reply of you (Give value to cus.prop. with equation.), which made me remind me of this thread :). I'm pretty confident that I can get my problem to work on that equation. However, it looks a bit too unstable ( /unsupportde ;p) for what I have to do. So I went on googling a bit etc. Now I pretty much now how to get it to work in VBA. The thing I have no knowledge about is how to get this to work "OnRebuild".

So my question now is if anyone could give me some directions on how to get this to work (perheps with an existing macro, so I can filter that part out of it)

 
I actually thought of another way to solve this. I just make a macro with the text edit part and in the end I put in the Rebuild command. This is what I have so far and it seems to be working pretty nice. I just need to build in some more checks for the "SOMETEXT" string.

Code:
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cpm As CustomPropertyManager

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set cpm = swModel.Extension.CustomPropertyManager("")
    
    Dim PartNo_ValOut As String
    Dim PartNo_Resolvedvalout As String
    Dim PartNo2 As String
    Dim boolstatus As Boolean
    
    cpm.Get2 "PartNo", PartNo_ValOut, PartNo_Resolvedvalout
    
    If StrComp(Left(Right(PartNo_Resolvedvalout, 4), 3), "REV") = 0 Then
        cpm.Delete "PartNo2"
        cpm.Add2 "PartNo2", swCustomInfoText, Left(PartNo_Resolvedvalout, Len(PartNo_Resolvedvalout) - 5)
    Else
        cpm.Add2 "PartNo2", swCustomInfoText, "!PARTNO ERROR!"
    End If
        
    boolstatus = swModel.EditRebuild3()
    
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor