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 have done something similar with what we refer to as "Bucket Documents". They are basically pools of documents that sit under one class and are sub-categorised by document type. This would be similar to what you are trying to achieve.

    I was going down the path of using the project # in the title of a document and it soon developed in to a problem with the lenght of the file names becoming too long and then the issue of 256 character limitation within Windows causes and issue and files seem to disappear, even though they are there. I found it best to set up common views that group the files by properties such as project. If you are trying to use the M-files properties as fields in your documents for titles or something similar, it's easy enough to just place two fields instead of one in the document.

    Anyway, this is the code that I have managed to get working the way I want with the help of some of the great people on this forum. I too am a relative beginner when it comes to VBS, but I have managed to get this working, I'm sure some of the experts on here could simplify my code down if necessary :)

    Enjoy your M-Files journey!


    Option Explicit
    Dim dtBucketTitle 'get the current title of the document if it exists.
    dtBucketTitle = PropertyValues.SearchForProperty ( 1043 ).TypedValue.GetValueAsLocalizedText ()
    Dim index
    index = InStr(dtBucketTitle,"-") 'find the position of the leading characters of the file
    If index > 0 then
    Dim szTest
    szTest = Left(dtBucketTitle,3) 'check to see if it is a valid "Bucket document" currently by the prefix
    If szTest = "DRW" or szTest = "DXO" or szTest = "EBT" or szTest = "FRM" or szTest = "HAZ" or szTest= "TMP" or szTest = "TRG" or szTest = "WI " then
    Dim dtDocName1
    dtDocName1 = PropertyValues.SearchForProperty ( 1038 ).TypedValue.GetValueAsLocalizedText ()
    Dim dtDocNum
    dtDocNum = PropertyValues.SearchForProperty ( 1037 ).TypedValue.GetValueAsLocalizedText ()
    Output = dtDocNum & ": " & dtDocName1 're-concatenate the current document # and name to give the full file name.
    Else
    Call GenerateNo 'create a new document number and name if above conditions are not met
    End If
    Else
    Call GenerateNo 'create a new document number and name if nothing exists
    End If
    '-----------------------------------------------------------------
    Sub GenerateNo

    Dim dtDocName 'get the document name
    dtDocName = PropertyValues.SearchForProperty ( 1038 ).TypedValue.GetValueAsLocalizedText ()
    Dim dtDocType 'get the document type
    dtDocType = PropertyValues.SearchForProperty ( 1034 ).TypedValue.GetValueAsLocalizedText ()
    Dim dtCount 'the following 3 steps sets up parts of the name for the vaultsharedvariable by finding the leading characters, and section#
    dtCount = InStr(dtDocType,"-")
    Dim dtAbbrDocType
    dtAbbrDocType = Left(dtDocType,dtCount-2)
    Dim dtSectNo
    dtSectNo = "S" & Left(PropertyValues.SearchForProperty ( 1028 ). TypedValue.GetValueAsLocalizedText,2)
    Dim Counter 'set the full vaultsharedvariable name
    Counter = dtAbbrDocType & dtSectNo
    Dim nnn,SectCounter 'set the counter to the current vaultsharedvariable value
    SectCounter = VaultSharedVariables(Counter)
    'the counter sets to 1 if this is the first time this vaultshared variable is used (3 digits set below in output)
    IF IsNull(SectCounter) or IsEmpty(SectCounter) or SectCounter = "" Then
    nnn=1
    Else
    nnn = CInt(Right(SectCounter,3)) + 1 'increment counter by 1 for a new document
    End IF
    VaultSharedVariables (Counter) = nnn 'store the current count in the vault shared variable
    'concatenate the document type, the document section #, and the 3 digits for the # count followed by the document name i.e. FRM-S01-001: Test Form
    Output = dtAbbrDocType & "-" & dtSectNo & "-" & Right ("000" & nnn,3) & ": " & dtDocName
    End Sub
Reply
  • Former Member
    Former Member
    Hi ayhoom,

    I have done something similar with what we refer to as "Bucket Documents". They are basically pools of documents that sit under one class and are sub-categorised by document type. This would be similar to what you are trying to achieve.

    I was going down the path of using the project # in the title of a document and it soon developed in to a problem with the lenght of the file names becoming too long and then the issue of 256 character limitation within Windows causes and issue and files seem to disappear, even though they are there. I found it best to set up common views that group the files by properties such as project. If you are trying to use the M-files properties as fields in your documents for titles or something similar, it's easy enough to just place two fields instead of one in the document.

    Anyway, this is the code that I have managed to get working the way I want with the help of some of the great people on this forum. I too am a relative beginner when it comes to VBS, but I have managed to get this working, I'm sure some of the experts on here could simplify my code down if necessary :)

    Enjoy your M-Files journey!


    Option Explicit
    Dim dtBucketTitle 'get the current title of the document if it exists.
    dtBucketTitle = PropertyValues.SearchForProperty ( 1043 ).TypedValue.GetValueAsLocalizedText ()
    Dim index
    index = InStr(dtBucketTitle,"-") 'find the position of the leading characters of the file
    If index > 0 then
    Dim szTest
    szTest = Left(dtBucketTitle,3) 'check to see if it is a valid "Bucket document" currently by the prefix
    If szTest = "DRW" or szTest = "DXO" or szTest = "EBT" or szTest = "FRM" or szTest = "HAZ" or szTest= "TMP" or szTest = "TRG" or szTest = "WI " then
    Dim dtDocName1
    dtDocName1 = PropertyValues.SearchForProperty ( 1038 ).TypedValue.GetValueAsLocalizedText ()
    Dim dtDocNum
    dtDocNum = PropertyValues.SearchForProperty ( 1037 ).TypedValue.GetValueAsLocalizedText ()
    Output = dtDocNum & ": " & dtDocName1 're-concatenate the current document # and name to give the full file name.
    Else
    Call GenerateNo 'create a new document number and name if above conditions are not met
    End If
    Else
    Call GenerateNo 'create a new document number and name if nothing exists
    End If
    '-----------------------------------------------------------------
    Sub GenerateNo

    Dim dtDocName 'get the document name
    dtDocName = PropertyValues.SearchForProperty ( 1038 ).TypedValue.GetValueAsLocalizedText ()
    Dim dtDocType 'get the document type
    dtDocType = PropertyValues.SearchForProperty ( 1034 ).TypedValue.GetValueAsLocalizedText ()
    Dim dtCount 'the following 3 steps sets up parts of the name for the vaultsharedvariable by finding the leading characters, and section#
    dtCount = InStr(dtDocType,"-")
    Dim dtAbbrDocType
    dtAbbrDocType = Left(dtDocType,dtCount-2)
    Dim dtSectNo
    dtSectNo = "S" & Left(PropertyValues.SearchForProperty ( 1028 ). TypedValue.GetValueAsLocalizedText,2)
    Dim Counter 'set the full vaultsharedvariable name
    Counter = dtAbbrDocType & dtSectNo
    Dim nnn,SectCounter 'set the counter to the current vaultsharedvariable value
    SectCounter = VaultSharedVariables(Counter)
    'the counter sets to 1 if this is the first time this vaultshared variable is used (3 digits set below in output)
    IF IsNull(SectCounter) or IsEmpty(SectCounter) or SectCounter = "" Then
    nnn=1
    Else
    nnn = CInt(Right(SectCounter,3)) + 1 'increment counter by 1 for a new document
    End IF
    VaultSharedVariables (Counter) = nnn 'store the current count in the vault shared variable
    'concatenate the document type, the document section #, and the 3 digits for the # count followed by the document name i.e. FRM-S01-001: Test Form
    Output = dtAbbrDocType & "-" & dtSectNo & "-" & Right ("000" & nnn,3) & ": " & dtDocName
    End Sub
Children
No Data