Automatic personal property information

    Hi all

 

  I come here to present you with an idea that I cannot put into practice.

 

 Let me explain: I have a custom property form where I fill in the name of the client, his site reference, and various other information.

 

I would like Solidworks to automatically fetch the name of the folder in which the part is saved, which will become the site reference.

 

Then he should go and get the name of the parent file from it, which will become the name of the client.

 

So I found quite easily how to fill in the path of the folder, but it gives me something like c:/plan/lambda client/ref x.

 

Is there a way either to choose in this path which characters to appear, or to enter a formula directly as requested above?

 

I hope I have been clear in my explanation.

 

Thanks in advance

 

Do you use EPDM???

 

If so, I know that there is a relatively simple technique but I don't remember it too much, I have to look at the templates that have been set up in our company.

1 Like

Unfortunately, I don't use EPDM...

arff..

 

I'll do a little research but there... I dry

Do you have any regard with SmartProperties?

I've already asked this question on several forums, and a lot of people are dry...

 

 

apparently impossible? I doubt it... Or maybe in a future update who it is?

 

 

To answer, I go through the 2014 property form editor.

 

Thank you again.

 

 

Hello

 

I don't think it's possible in automatic, so you'll have to go through a macro.

 

To get started with VBA macro for SolidWorks, watch my tutorial if you haven't already:

http://www.lynkoa.com/tutos/3d/macro-enregistrer-sous-avec-solidworks

 

I think I use the file path at least 2 times (path in the macro).

 

And a lead for your problem (not tested):

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

swModel.AddCustomInfo2 "File Path", swCustomInfoText, Left(swModel.GetPathName,InStrRev(swModel.GetPathName, "\"))

End Sub

 

Spring:

https://forum.solidworks.com/thread/42839

 

 

 

 

 

 

3 Likes

I think it's doable if in the file path you have all your information (Client and site ref).

 

You create a temporary property that retrieves your path and then with the Smartproperties utility and the "string type" function  you retrieve your customer name, your site ref, etc.....


type_chaine_de_caractere.png
7 Likes

Here's an example, how to create a property with the folder name

 

Imports SolidWorks.Interop

Imports SolidWorks.Interop.swconst

Imports System.Runtime.InteropServices

Imports System

 

Partial Class SolidWorksMacro

    ''' <summary>

    ''' The SldWorks swApp variable is pre-assigned for you.

    ''' </summary>

    Public swApp As sldworks. SldWorks

 

    Public Sub main()

 

        Dim swDoc As sldworks. ModelDoc2 = Nothing

 

        ' Active Document

        swDoc = CType(swApp.ActiveDoc, sldworks. ModelDoc2)

 

        ' If there is an active document

        If swDoc Is Nothing Then Exit Sub

 

        ' If the document has already been registered

        If Not IO. File.Exists(swDoc.GetPathName) Then Exit Sub

 

        ' Place the folder levels in a table (1st element => Disk, last element => file name)

        Dim stFolders As Array = swDoc.GetPathName.Split("\")

 

        Dim stParentFolder As String = stFolders(stFolders.Length - 2)

 

        AddProperty(swDoc, "Name", stParentFolder)

 

    End Sub

 

    Function AddProperty(ByVal _Doc As sldworks. ModelDoc2, ByVal _Name As String, ByVal _Value As String) As Boolean

        Dim swCustProp As sldworks. ICustomPropertyManager = _Doc.Extension.CustomPropertyManager("")

         ' Dim iAdd As Integer = swCustProp.Add3(_Name, swCustomInfoType_e.swCustomInfoText, _Value, swCustomPropertyAddOption_e.swCustomPropertyReplaceValue)

        Dim iAdd As swCustomInfoType_e = swCustProp.Add2(_Name, swCustomInfoType_e.swCustomInfoText, _Value)

        If iAdd <> 1 Then

            swCustProp.Set(_Name, _Value)

        End If

 

    End Function

 

 

End Class


swmacro.zip
11 Likes

I'm not an expert in VBA programming but I still took over Jfaradon's last post.

 

But on line 2 I find a compilation error....

 

I'm going to read tutorials on the vba to see if that's the way I should go

 

Thank you again, I'll get back to you soon!


vba.png

 

you can't copy and paste into VBA like on the screenshot

 

Retrieve the zip and open the project SwMacro.sln

it's VSTA ... not VBA (there are two macro tools on SW)

 

9 Likes

There is no SwMacro.sln project in your zip.

 

 

Hello

 

For me the best solution is the one described by Flegendre.

In any case, it's the one I apply to us.

It's simple and it works very well!!

Yes emathubert, except that I don't have smartproperties !!

Sorry, open the .vbproj !!

See screenshot

 

.sln it's with the Visual Studio tool

 


sans_titre_-_1.jpg
2 Likes

Still no solution? ... =)

Hello Bart,

I don't know if it could help you but I came across this link recently:

http://www.leguide3d.com/profiles/blogs/concat-nation-de-propri-t-s-personnalis-s

It could, a priori, be used to do the opposite, i.e. have a "client" property, a "ref" property and thus create your path by associating these properties.

Regarding the extraction from the path, do you manage to recover the path of the room in a property?
Do you use a room family table? This could be useful for extracting properties in Excel

Other avenues: 

https://forum.solidworks.com/message/306923#306923#306923

https://forum.solidworks.com/message/133512#133512#133512

http://www.forum-cao-3d.fr/api-questions/extraction-reference-solidworks-t12149.html

 

Have you managed to do anything with @jfaradon's macros?

(I'm currently working on the same topic)

1 Like

This is a subject that I do as a common thread, because it is practical but not vital either.

 

On the other hand, I'll get back to it here, as I have a little time ahead of me =)

 

I can retrieve the name of the folder where the MEP is saved, but with its full path.

that is to say: C:/Solidworks plans/ClientX/ChaniterY/caseZ/....

 

I'll look at all this and keep you posted;)