Hot News:

Mit Unterstützung durch:

  Foren auf CAD.de
  CATIA V5 Programmierung
  Hilfe mit makro.

Antwort erstellen  Neues Thema erstellen
CAD.de Login | Logout | Profil | Profil bearbeiten | Registrieren | Voreinstellungen | Hilfe | Suchen

Anzeige:

Darstellung des Themas zum Ausdrucken. Bitte dann die Druckfunktion des Browsers verwenden. | Suche nach Beiträgen nächster neuer Beitrag | nächster älterer Beitrag
  
Gut zu wissen: Hilfreiche Tipps und Tricks aus der Praxis prägnant, und auf den Punkt gebracht für CATIA & Co.
  
KISTERS 3DViewStation - Der Schlüssel zur Einsparung von CAD-Lizenzen, eine Pressemitteilung
Autor Thema:  Hilfe mit makro. (3273 mal gelesen)
xyon126
Mitglied
Ingenieur


Sehen Sie sich das Profil von xyon126 an!   Senden Sie eine Private Message an xyon126  Schreiben Sie einen Gästebucheintrag für xyon126

Beiträge: 74
Registriert: 07.11.2011

erstellt am: 07. Nov. 2011 10:39    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities

Hallo!
          Verzeihen Sie meine Sprache ist Deutsch, aber sehr schwierig für mich, obwohl ich zu benutzen, wann immer ich kann es versuchen.

Wenn möglich Ich mag würde, um sie in einem Makro helfen, ich habe ein Makro "Parts" und es funktioniert perfekt und ich will es rekursive von einem "Produkt" ausführen und die Antwort aller Teile eines einzigen Klick. Das Makro funktioniert extrahieren einen String in die Datei benennen und speichern auf dem Grundstück "Definition" ersetzt das "_" für Punkte. Das Problem ist, dass nicht viel CatScript Domain und gibt mir Fehler kontinuierlich, können Sie helfen?

Das ist der Code von PART OK

Code:

Language="VBSCRIPT"

Sub CATMain()

' Obtener documento o CATPart activa.
    Dim docPart as PartDocument
    Set docPart = CATIA.ActiveDocument

    ' Tener acceso al documento o CATPart activa.
    Dim prdPart as Part
    Set prdPart = docPart.Product
   
' Obtener el nombre de la CATPart activa.
    Dim productDocument1 As Document
    Set productDocument1 = CATIA.ActiveDocument
    Textdata = productDocument1.Name

Textdata = Left(productDocument1.Name, 16)

Textdata = right(Textdata, 10)

Textdata = Replace(Textdata, "_", ".")

productDocument1.Product.Definition = Textdata

End Sub



Und das meine Kopfschmerzen

Code:

Language="VBSCRIPT"

Sub CATMain()

'Obtener el objeto de selección
Dim objSelection as Selection
Set objSelection = CATIA.ActiveDocument.Selection

'Búsqueda de productos
objSelection.Search "'Assembly Design'.Product,all"

'Loop Recorrer todos los productos que se encuentran
Dim prdProduct as Product
Dim iProduct

For iProduct=1 to objSelection.Count

    ' Obtiene el siguiente producto de la selección
Set prdProduct = objSelection.Item(iProduct).Value
   
    'Obtener el objeto de selección
     Dim objSelectionPart as Selection
     Set objSelectionPart = CATIA.ActiveDocument.Selection

    'Búsqueda de Parts
     objSelectionPart.Search "'CATIAPart'.Part,all"
   
    'Loop Recorrer todos los parts que se encuentran
     Dim prdPart as Part
     Dim iPart
     Set prdPart = docPart.Product
   
     For iprdPart=1 to objSelectionPart.Count
    
        call EditarDefinition
       
     Next
  
Next

MsgBox  "Propertis Definition editadas en todos los CATParts"

End Sub

Sub EditarDefinition()


' Obtener documento o CATPart activa.
    Dim docPart as PartDocument
    Set docPart = CATIA.ActiveDocument

' Obtener el nombre de la CATPart activa.
    Dim productDocument1 As Document
    Set productDocument1 = CATIA.ActiveDocument
   
   
'--------------------------------
' EDITAR LA PROPIEDAD DEFINITION
'--------------------------------
   
   
Textdata = productDocument1.Name
Textdata = Left(productDocument1.Name, 16)
Textdata = right(Textdata, 10)
Textdata = Replace(Textdata, "_", ".")

MsgBox (Textdata)

productDocument1.Product.Definition = Textdata


End Sub



Vielen Dank im Voraus

[Diese Nachricht wurde von xyon126 am 07. Nov. 2011 editiert.]

Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

RSchulz
Ehrenmitglied V.I.P. h.c.
Head of CAD, Content & Collaboration / IT-Manager



Sehen Sie sich das Profil von RSchulz an!   Senden Sie eine Private Message an RSchulz  Schreiben Sie einen Gästebucheintrag für RSchulz

Beiträge: 5541
Registriert: 12.04.2007

@Work
Lenovo P510
Xeon E5-1630v4
64GB DDR4
Quadro P2000
256GB PCIe SSD
512GB SSD
SmarTeam V5-6 R2016 Sp04
CATIA V5-6 R2016 Sp05
E3.Series V2019
Altium Designer/Concord 19
Win 10 Pro x64

erstellt am: 07. Nov. 2011 11:52    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities Nur für xyon126 10 Unities + Antwort hilfreich

Hello,
maybe english could be the better choice. I hope you´ll understand   Additional for understanding it could be better to write the information lines in english. However did you run the script in stepbystep mode via the F8-Key? The Question is what kind of error it is and in which line it occurs. In the most cases it would be necessary for finding out what the problem is...

Code:

Sub CATMain()

'Obtener el objeto de selección
Dim objSelection as Selection
Set objSelection = CATIA.ActiveDocument.Selection

'Búsqueda de productos
objSelection.Search "'Assembly Design'.Product,all"

'Loop Recorrer todos los productos que se encuentran
Dim prdProduct as Product
Dim iProduct

For iProduct=1 to objSelection.Count

    ' Obtiene el siguiente producto de la selección
Set prdProduct = objSelection.Item(iProduct).Value
   
    'Obtener el objeto de selección
     Dim objSelectionPart as Selection
     Set objSelectionPart = CATIA.ActiveDocument.Selection

    'Búsqueda de Parts
     objSelectionPart.Search "'CATIAPart'.Part,all"
   
    'Loop Recorrer todos los parts que se encuentran
     Dim prdPart as Part
     Dim iPart
     Set prdPart = docPart.Product
   
     For iprdPart=1 to objSelectionPart.Count
    
        call EditarDefinition
       
     Next
  
Next

MsgBox  "Propertis Definition editadas en todos los CATParts"

End Sub

Sub EditarDefinition()


' Obtener documento o CATPart activa.
    Dim docPart as PartDocument
    Set docPart = CATIA.ActiveDocument

' Obtener el nombre de la CATPart activa.
    Dim productDocument1 As Document
    Set productDocument1 = CATIA.ActiveDocument

   
   
'--------------------------------
' EDITAR LA PROPIEDAD DEFINITION
'--------------------------------
   
   
Textdata = productDocument1.Name
Textdata = Left(productDocument1.Name, 16)
Textdata = right(Textdata, 10)
Textdata = Replace(Textdata, "_", ".")

MsgBox (Textdata)

productDocument1.Product.Definition = Textdata


End Sub


I found out some problems in the code.

All the time you are using the selection of the active document but you did not activate an other document. So all your selections use the same selection object. This could not work i think.

Additional the search routine (objSelectionPart.Search "'CATIAPart'.Part,all") is not defined correctly but i did not know for what you are searching for.

The Function "EditarDefinition()" could not work correctly because in all cases you are using the same (active) document instead of a defined document.

It´s not possible to find a solution with such a bad information. You have to define the functions of your program. Maybe then we could help you.

------------------
MFG
Rick Schulz

Nettiquette (CAD.de)  -  Was ist die Systeminfo?  -  Wie man Fragen richtig stellt.  -  Unities

Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

xyon126
Mitglied
Ingenieur


Sehen Sie sich das Profil von xyon126 an!   Senden Sie eine Private Message an xyon126  Schreiben Sie einen Gästebucheintrag für xyon126

Beiträge: 74
Registriert: 07.11.2011

erstellt am: 07. Nov. 2011 12:21    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities

Hello R. Schulz!

      Thank you for your prompt response. on the language used, the Spanish do not have much facility with languages ​​(problems of basic education) and is the same English or German.

On the macro, the first works for me perfectly, does the following:

Filename: 2172D_10_010_000__00___BG_ATORNILLADO_ADAPTER_MHS_29102011.CATPart

draws the string "10_010_000" translates to "10.010.000" and writes it to the window "Properties> Product> Definition".

For this I want to do from a product that has several Products, each with 7 or 8 CatParts.

This would be the code that gives me problems.

Code:
Language="VBSCRIPT"

Sub CATMain()

'Get the selection object
Dim objSelection as Selection
Set objSelection = CATIA.ActiveDocument.Selection

'Product Search
objSelection.Search "'Assembly Design'.Product,all"

'Loop through all the products
Dim prdProduct as Product
Dim iProduct

For iProduct=1 to objSelection.Count

    ' Get the next product of selection
Set prdProduct = objSelection.Item(iProduct).Value
   
    'Get the selection object
    Dim objSelectionPart as Selection
    Set objSelectionPart = CATIA.ActiveDocument.Selection

    'Search for Parts
    objSelectionPart.Search "'CATIAPart'.Part,all"
   
    'Loop through all the parts
    Dim prdPart as Part
    Dim iPart
    Set prdPart = docPart.Product
   
    For iprdPart=1 to objSelectionPart.Count
   
        call EditDefinition
       
    Next
 
Next

MsgBox  "Definition Property edited"

End Sub

Sub EditDefinition()


' Get active document or CATPart.
    Dim docPart as PartDocument
    Set docPart = CATIA.ActiveDocument

' Get the name of the active CATPart.
    Dim productDocument1 As Document
    Set productDocument1 = CATIA.ActiveDocument
   
   
'--------------------------------
' EDIT PROPERTY DEFINITION
'--------------------------------
   
   
Textdata = productDocument1.Name
Textdata = Left(productDocument1.Name, 16)
Textdata = right(Textdata, 10)
Textdata = Replace(Textdata, "_", ".")

'MsgBox (Textdata)

productDocument1.Product.Definition = Textdata


End Sub


The error that I get are two:

        CATIASelection.
        The method Search failed.

in the line of code

Code:
'Búsqueda de Parts
    objSelectionPart.Search "'CATIAPart'.Part,all"

And the other

have detected that you, always select the same Part.

How I can fix them?

Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

RSchulz
Ehrenmitglied V.I.P. h.c.
Head of CAD, Content & Collaboration / IT-Manager



Sehen Sie sich das Profil von RSchulz an!   Senden Sie eine Private Message an RSchulz  Schreiben Sie einen Gästebucheintrag für RSchulz

Beiträge: 5541
Registriert: 12.04.2007

@Work
Lenovo P510
Xeon E5-1630v4
64GB DDR4
Quadro P2000
256GB PCIe SSD
512GB SSD
SmarTeam V5-6 R2016 Sp04
CATIA V5-6 R2016 Sp05
E3.Series V2019
Altium Designer/Concord 19
Win 10 Pro x64

erstellt am: 07. Nov. 2011 13:21    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities Nur für xyon126 10 Unities + Antwort hilfreich

Hello,
I think the following code could do what you are looking for...

Code:

Sub CATMain()

    'create document object
    Dim tmpDoc As Document

    'each opened document should be selected
    For Each tmpDoc In CATIA.Documents

        'only parts and products should be changed
        If InStr(1, tmpDoc.Name, ".CATProduct") > 0 Or InStr(1, tmpDoc.Name, ".CATPart") > 0 Then
       
            'change selected document
            Textdata = tmpDoc.Name
            Textdata = Left(tmpDoc.Name, 16)
            Textdata = Right(Textdata, 10)
            Textdata = Replace(Textdata, "_", ".")
            tmpDoc.Product.Definition = Textdata
       
        End If
   
    Next

End Sub


Hope that helps...

------------------
MFG
Rick Schulz

Nettiquette (CAD.de)  -  Was ist die Systeminfo?  -  Wie man Fragen richtig stellt.  -  Unities

Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

xyon126
Mitglied
Ingenieur


Sehen Sie sich das Profil von xyon126 an!   Senden Sie eine Private Message an xyon126  Schreiben Sie einen Gästebucheintrag für xyon126

Beiträge: 74
Registriert: 07.11.2011

erstellt am: 07. Nov. 2011 15:13    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities

Guauuuuuuuuu!

          It works perfectly, you're the best, just one question since what matters to me now is to learn.
          I see you've summed up the code to more than half but as you did the loop to open all the Parts?
          Could you explain a bit the code.


Code:
'change selected document
            Textdata = tmpDoc.Name
            Textdata = Left(tmpDoc.Name, 16)
            Textdata = Right(Textdata, 10)
            Textdata = Replace(Textdata, "_", ".")
            tmpDoc.Product.Definition = Textdata


if the code being gradually phased "'change selected document" on the other, I served as a recursive (loop)?

Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

RSchulz
Ehrenmitglied V.I.P. h.c.
Head of CAD, Content & Collaboration / IT-Manager



Sehen Sie sich das Profil von RSchulz an!   Senden Sie eine Private Message an RSchulz  Schreiben Sie einen Gästebucheintrag für RSchulz

Beiträge: 5541
Registriert: 12.04.2007

@Work
Lenovo P510
Xeon E5-1630v4
64GB DDR4
Quadro P2000
256GB PCIe SSD
512GB SSD
SmarTeam V5-6 R2016 Sp04
CATIA V5-6 R2016 Sp05
E3.Series V2019
Altium Designer/Concord 19
Win 10 Pro x64

erstellt am: 07. Nov. 2011 15:32    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities Nur für xyon126 10 Unities + Antwort hilfreich

Thanks 

For such a change in the documents you do not have to read the entire stucture of an assembly because you do not need a selection box or something else for manually selecting documents. Either way you want to change that entries for all opened documents. So what have I done is to read the opened documents with a for each loop which automatically selects the documents for me as object tmpDoc. Then I check that the selected document is a "CATPart" or "CATProduct" and if this check succeed i change the definition entry.

------------------
MFG
Rick Schulz

Nettiquette (CAD.de)  -  Was ist die Systeminfo?  -  Wie man Fragen richtig stellt.  -  Unities

Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

xyon126
Mitglied
Ingenieur


Sehen Sie sich das Profil von xyon126 an!   Senden Sie eine Private Message an xyon126  Schreiben Sie einen Gästebucheintrag für xyon126

Beiträge: 74
Registriert: 07.11.2011

erstellt am: 07. Nov. 2011 15:59    Editieren oder löschen Sie diesen Beitrag!  <-- editieren / zitieren -->   Antwort mit Zitat in Fett Antwort mit kursivem Zitat    Unities abgeben: 1 Unity (wenig hilfreich, aber dennoch)2 Unities3 Unities4 Unities5 Unities6 Unities7 Unities8 Unities9 Unities10 Unities

change the Part one I have it clear, when session is always complete with respect Products and Parts, because as you have seen me trying to do a "For" for the Products and in this "For" but one for Parts I see that your system is clean and fast and does exactly the same. I understand you correctly?

M.f.G.

Manuel

Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP

Anzeige.:

Anzeige: (Infos zum Werbeplatz >>)

Darstellung des Themas zum Ausdrucken. Bitte dann die Druckfunktion des Browsers verwenden. | Suche nach Beiträgen

nächster neuerer Beitrag | nächster älterer Beitrag
Antwort erstellen


Diesen Beitrag mit Lesezeichen versehen ... | Nach anderen Beiträgen suchen | CAD.de-Newsletter

Administrative Optionen: Beitrag schliessen | Archivieren/Bewegen | Beitrag melden!

Fragen und Anregungen: Kritik-Forum | Neues aus der Community: Community-Forum

(c)2025 CAD.de | Impressum | Datenschutz