hexagon logo

Ballooning script / Problem with "SetLine"

Hi everyone,

I wanted to write a script, that loops through all comments in PCDMIS and changes them accordingly...

We use Ballooned drawings and sometimes have 5 times the same dimension so we'd name them (for example dimension number 80) (80.1) / (80.2) / (80.3) ...
The script should correct multiple occurences automatically. So I would just have to put (80) each time in my comment and the script will keep track of every occurence and change them...

Allmost everything works fine; Unluckily i still have problems with the "SetLine" Command... Says "missing Argument(s)" but in the documentation i dont see any clue on what's going wrong.

Sub Main()
Dim PCDApp As Object
Dim PCDPartPrograms As Object
Dim PCDPartProgram As Object
Dim PCDCommands As Object
Dim PCDCommand As Object
Dim PCDComment As Object

Dim sContents As String
Dim iCnt As Integer
Dim j As Integer
Dim iCount As Integer
Dim num as Integer
Dim arr() as Integer


Set PCDApp = CreateObject("PCDLRN.Application")
Set PCDPartPrograms = PCDApp.PartPrograms
Set PCDPartProgram = PCDApp.ActivePartProgram
Set PCDCommands = PCDPartProgram.Commands

For iCnt = 1 To PCDCommands.Count
Set PCDCommand = PCDCommands.Item(iCnt)
If (PCDCommand.IsComment) Then
Set PCDComment = PCDCommand.CommentCommand
If (PCDComment.CommentType = 1) And (inStr(1,PCDComment.Comment,"Aln")<1)Then
For j = 1 To 10
If (PCDComment.GetLine(j)="") Then Exit For
sContents = PCDComment.GetLine(j)
MsgBox sContents 'Bulle mit Klammern
sContents = Replace(sContents, "(", "")
sContents = Replace(sContents, ")", "")
MsgBox sContents 'Bulle ohne Klammern
If IsNumeric(sContents) Then
num = sContents
ReDim Preserve arr(num)
arr(num) = arr(num) + 1
sContents = "(" & num & "." & arr(num) & ")"
MsgBox sContents 'Angepasste Bulle mit Klammern
PCDComment.SetLine(j,sContents) 'funktioniert nicht...
End If
Next
End If
End If
Next iCnt
End Sub


Any Ideas?
  • Try

    result=PCDComment.SetLine(j, sContents)
    


    Additionally, you should use underscore instead of point or comma as separator. Less headache for you.
  • Thank you for your input!
    You mean

    result=PCDComment.SetLine(j, sContents)


    instead of

    PCDComment.SetLine(j,sContents)


    ?
  • Dim retVal
    retVal = PCDComment.SetLine(j, sContents)
    instead of "PCDComment.SetLine(j,sContents)"

    sometimes the functions won't work properly if they don't return their values
    try it like this
  • Ok, now I see what you both mean, thanks
  • Thanks again! I just tested it and it works just perfectly :-)

    Just had to be able to put its return somewhere.
  • I just did some extended testing and there's still a problem somewhere...

    It iterates the occurences of my balloonings, but in some situations it doesnt...

    I started with this:

    KOMMENTAR/PROT,
    (20)
    (30)
    (40)
    KOMMENTAR/PROT,
    (30)
    (20)
    KOMMENTAR/PROT,
    (50)
    (40)
    (40)

    and i got this in the end:

    KOMMENTAR/PROT,
    (20.1)
    (30.1)
    (40.1)
    KOMMENTAR/PROT,
    (30.2)
    (20.2)
    KOMMENTAR/PROT,
    (50.1)
    (40.1)
    (40.2)​

    As you can see, the (20)s and (30)s are just fine, but the 40 seems to work only when multiple occurences are in the same comment but not if they're separated...​

    -------------------------------------
    KOMMENTAR/PROT,
    (20)
    (30)
    (40)
    KOMMENTAR/PROT,
    (30)
    (20)
    (40)
    KOMMENTAR/PROT,
    (50)
    (40)
    (40)

    gets

    KOMMENTAR/PROT,
    (20.1)
    (30.1)
    (40.1)
    KOMMENTAR/PROT,
    (30.2)
    (20.2)
    (40.1)
    KOMMENTAR/PROT,
    (50.1)
    (40.2)
    (40.3)​​

    In this example it still iterated the "40" from the 2nd to the 3rd Comment but not at the beginning...
  • good Day,

    the pcDMIS basic.dll / compiler is a bit wonky.
    I 've had bad experiences with arrays, and I would recommend that you avoid them altogether in pcDMIS scripts
    auto convert combined with arrays rarely works, prefer to use Cint Cstr etc

    well,

    a bit exaggerated but here a string is used as an array substitute:
      Dim PCDApp As Object
      Dim PCDPartPrograms As Object
      Dim PCDPartProgram As Object
      Dim PCDCommands As Object
      Dim PCDCommand As Object
      Dim PCDComment As Object
    
      Dim sContents As String
      Dim iCnt As Integer
      Dim j, k, n As Integer
      Dim iCount As Integer
      Dim num As Integer
    
      Dim sArrayErsatz, S, S2 As String
      Dim retVal
    
      Set PCDApp = CreateObject("PCDLRN.Application")
      Set PCDPartPrograms = PCDApp.PartPrograms
      Set PCDPartProgram = PCDApp.ActivePartProgram
      Set PCDCommands = PCDPartProgram.Commands
    
      sArrayErsatz = ""
      For iCnt = 1 To PCDCommands.count
        Set PCDCommand = PCDCommands.Item(iCnt)
        If (PCDCommand.IsComment) Then
          Set PCDComment = PCDCommand.CommentCommand
          If (PCDComment.CommentType = 1) And (InStr(1, PCDComment.Comment, "Aln") < 1) Then
            For j = 1 To 10
              If (PCDComment.GetLine(j) = "") Then Exit For
              
              sContents = PCDComment.GetLine(j)
              'MsgBox sContents 'Bulle mit Klammern
              sContents = Replace(sContents, "(", "")
              sContents = Replace(sContents, ")", "")
              'MsgBox sContents 'Bulle ohne Klammern
              
              If IsNumeric(sContents) Then
                num = CInt(sContents)
                k = InStr(1, sArrayErsatz, CStr(num) + ".")
                If k = 0 Then
                  S = "1"
                  sArrayErsatz = sArrayErsatz + CStr(num) + ".1;"
                End If
                If k > 0 Then
                  n = InStr(k, sArrayErsatz, ";")
                  S2 = Mid(sArrayErsatz, k, n - k + 1)
                  k = InStr(k, sArrayErsatz, ".")
                  S = Mid(sArrayErsatz, k + 1, n - k - 1)
                  If IsNumeric(S) Then S = CStr(CInt(S) + 1)
                  sArrayErsatz = Replace(sArrayErsatz, S2, CStr(num) + "." + S + ";")
                End If
                sContents = "(" & CStr(num) + "." + S & ")"
                'MsgBox sContents 'Angepasste Bulle mit Klammern
                retVal = PCDComment.SetLine(j, sContents)
              End If
            Next
          End If
        End If
      Next iCnt​
    
  • Gets me an error on line 53 "Function not found". That would be the replace command. I dont find it in the supported list on:
    https://docs.hexagonmi.com/pcdmis/2019.1/en/helpcenter/mergedProjects/basic/Language_Reference_A_to_Z.htm
    So i guess PCDMIS doesnt support it right?
  • Before the error however it does this...
    Comments:
    KOMMENTAR/PROT,
    (20)
    (30)
    (40)
    KOMMENTAR/PROT,
    (30)
    (20)
    (40)
    KOMMENTAR/PROT,
    (50)
    (40)
    (40)
    KOMMENTAR/PROT,
    (20)
    KOMMENTAR/PROT,
    (40):

    Output:
    KOMMENTAR/PROT,
    (20.1)
    (30.1)
    (40.1)
    KOMMENTAR/PROT,
    (30)
    (20)
    (40)
    KOMMENTAR/PROT,
    (50)
    (40)
    (40)
    KOMMENTAR/PROT,
    (20)
    KOMMENTAR/PROT,
    (40)

    So the first time it encounters a second occurence it makes the error
  • I never worked with it, but a scripting dictionary could work too i think (if it's supported by PCDMIS)
    I'll have to do some testing :-)

    EDIT: Scripting dictionary doesnt seem to work.