This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Automatic Drawing Naming Standard

Former Member
Former Member
Hello! I just got m-files up and running, so I'm fairly new the VBscript on it. I'm hoping someone could help me out with my code.

I would like to automatically name all drawings in the class "Drawings" that are inserted based on two properties and an auto number.
Property 1: Drawing type (value list consisting of "ELE", "MEC", "CIV", "STR", etc.)
Property 2: Project (choose from list of existing Projects)
Auto-number: Counter which increments when documents by looking at other drawings of the same project having the same Property 1 & Property 2

For Example
Drawing 1
Drawing Type: ELE
Project: PARKING

=> Output: PARKING-ELE-01

Drawing 2
Drawing Type: ELE
Project: PARKING

=> Output: PARKING-ELE-02

Drawing 3
Drawing Type: MEC
Project: PARKING

=> Output: PARKING-MEC-01

And so on. So since a Document 1 exists with "PARKING" as a project and "ELE" as a drawing type, then Document 2 gets incremented by 1.

Is there anyone who has done something similar? I would really appreciate it if I could get some guidance with coding the Calculated Value (VBscript).

Thanks!

Parents
  • Former Member
    Former Member
    Hi ayhoom I prefer to post the response here to help anybody here in the community with the "same" problems...

    First of all I think that you want an autonumber that depend on Project + DrawingType + DrawingSize (correct me if I wrong) so you have to change the code that set [tt]cntname[/tt] because with that you wrote you build a counter based only to Project not on the other 2 properties!

    This maybe the correct code, and must be set after reading the 2 variables [tt]drwtyp[/tt] and [tt]drwsize[/tt]
    Dim prjname, cntname 
    prjname = PropertyValues.SearchForProperty( 1016 ).TypedValue.DisplayValue
    'here insert your correct code to read drwtyp and drwsize
    cntname = prjname & "|" & drwtyp & "|" & drwsize


    And than your main question about reading a property of another object based on the ID selected in a multi-select lookup property (as Project (1016) is) - for handle this you must use the method Vault.ObjectOperations.GetLatestObjectVersionAndProperties see more on this on M-Files API Documentation!

    Here is your "MISSING CODE"

    Dim projnum

    'read the ID of the selected project
    Dim multiIDs '
    Set multiIDs = PropertyValues.SearchForProperty( 1016 ).TypedValue.GetValueAsLookups()

    If multiIDs.Count > 0 Then
    'if something is selected by user - read the integer ID of the FIRST item selected (I believe that user select only one project!!!)
    Dim prjID '
    Set prjID = multiIDs.Item(1).Item

    'build and ObjID with the selected ID and the OBJECTTYPEID of the Project Object
    Dim ObjID
    Set ObjID = CreateObject("MFilesAPI.ObjID")
    ObjID.SetIDs PROJECT_OBJECTTYPE_ID, prjID '

    'get all properties of the Project selected
    Dim prjProps
    Set prjProps = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(ObjID, true, true)

    'and at the end read the projectnumber property that you are looking for
    prjnum = prjProps.Properties.SearchForProperty ( 1017 ).TypedValue.DisplayValue
    Else
    prjnum = ""
    End if


    I leave as an "exercise" to copy and past this new code in your previous prototype that is correct, and please test the entire code because I write it without possibility to debug!

    BR Lele (codbit)
Reply
  • Former Member
    Former Member
    Hi ayhoom I prefer to post the response here to help anybody here in the community with the "same" problems...

    First of all I think that you want an autonumber that depend on Project + DrawingType + DrawingSize (correct me if I wrong) so you have to change the code that set [tt]cntname[/tt] because with that you wrote you build a counter based only to Project not on the other 2 properties!

    This maybe the correct code, and must be set after reading the 2 variables [tt]drwtyp[/tt] and [tt]drwsize[/tt]
    Dim prjname, cntname 
    prjname = PropertyValues.SearchForProperty( 1016 ).TypedValue.DisplayValue
    'here insert your correct code to read drwtyp and drwsize
    cntname = prjname & "|" & drwtyp & "|" & drwsize


    And than your main question about reading a property of another object based on the ID selected in a multi-select lookup property (as Project (1016) is) - for handle this you must use the method Vault.ObjectOperations.GetLatestObjectVersionAndProperties see more on this on M-Files API Documentation!

    Here is your "MISSING CODE"

    Dim projnum

    'read the ID of the selected project
    Dim multiIDs '
    Set multiIDs = PropertyValues.SearchForProperty( 1016 ).TypedValue.GetValueAsLookups()

    If multiIDs.Count > 0 Then
    'if something is selected by user - read the integer ID of the FIRST item selected (I believe that user select only one project!!!)
    Dim prjID '
    Set prjID = multiIDs.Item(1).Item

    'build and ObjID with the selected ID and the OBJECTTYPEID of the Project Object
    Dim ObjID
    Set ObjID = CreateObject("MFilesAPI.ObjID")
    ObjID.SetIDs PROJECT_OBJECTTYPE_ID, prjID '

    'get all properties of the Project selected
    Dim prjProps
    Set prjProps = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(ObjID, true, true)

    'and at the end read the projectnumber property that you are looking for
    prjnum = prjProps.Properties.SearchForProperty ( 1017 ).TypedValue.DisplayValue
    Else
    prjnum = ""
    End if


    I leave as an "exercise" to copy and past this new code in your previous prototype that is correct, and please test the entire code because I write it without possibility to debug!

    BR Lele (codbit)
Children
No Data