1

There is a small error in my For loop as it will not select the part that I want to color. I used a variable hash to put all the names of the document there and then tried the Catia function to color, but still got nothing!

Below is a part fo the code. Problem zone is the Select Case. It wont actually select and color the part if found.

UPDATE: now i know exactly where the problem is, it is inside case during selection of the part and coloring it. somehow it wont even select the part.

For n = 1 To DokAnzahl
    Set Dokument = DokumentArray(n)

    ReDim DokumentArrayNew(DokAnzahl)
    DokumentArrayNew(n)  = CStr(Dokument.Name)

    For j = 1 To UBound(arrNamen)
        If arrNamenNew(j) = Left(DokumentArrayNew(n), Len(arrNamenNew(1))) Then
            'MsgBox "They are equal!"
            hash = DokumentArrayNew(n)
            ColorCode(j) = arrFarben(j)
            'MsgBox ColorCode(j) checked

            m = j+1

            Select Case ColorCode(j)
                Case "NEU" 'rot
                    Set sel = catia.activedocument.selection
                    sel.search "Name =hash,all"
                    sel.visproperties.setRealColor 240, 1, 1, 1
                Case "entfällt" 'Gelb
                    Set sel = catia.activedocument.selection
                    sel.search "Name =hash,all"
                    sel.visproperties.setRealColor 240, 240, 16, 1
                Case "COP" 'Grün
                    Set sel = catia.activedocument.selection
                    sel.search "Name =hash,all"
                    sel.visproperties.setRealColor 30, 240, 60, 1
                Case Else
                    MsgBox "no color info"
            End Select
        End If
    Next
Next
Sherlock Homies
  • 162
  • 1
  • 9
  • What is the point of putting your documents in the array DocumentArrayNew ? You consume the document object right away and the array seems unnecessary. And, Document is an object, when you assign one to hash you should be using the "Set" keyword . Also, Colors cannot be assigned to Document objects. Typically you assign colors to products in an assembly or bodies in a Part. – C R Johnson Jul 12 '17 at 10:27
  • The Document name does not necessarily match the part number or part name in an assembly. Be careful with that. The main problem is when you search you are searching for somehing named "hash". You need to fix that searh query string so that it includes the value of instance name you are searching for. – C R Johnson Jul 12 '17 at 10:36
  • first of all thank you! I guess thats exactly where my problem is. The instance names do not match the part names. Is there a way to change my search query so it only looks for instancenames? – Sherlock Homies Jul 12 '17 at 10:55
  • i tried doing this : hash = Left(DokumentArrayNew(n),len(DokumentArrayNew(n)-1)) and i get error type conflict! – Sherlock Homies Jul 12 '17 at 11:33

1 Answers1

1

Your Selection.Search is searching for the word "Hash" and not what is inside the variable hash

Change your Select Case statements to this:

Set sel = catia.activedocument.selection
sel.search "Name =*" & hash & "*,all"
Quima
  • 894
  • 11
  • 21