Hallo zusammen,
ich habe ein kleines Problem mit einem Makro, mit dem ich mich schon seit letzter Woche quäle.
Diese Makro habe ich vor längerer Zeit aus dem Internet und für mich so umgesattelt das es meine benötigten Einträge ohne Fehlermeldung erstellt. Weil ich von der Makro Programmierung null Ahnung habe, steht mit Sicherheit auch viel unnützes drin.
Mit dem Makro lege ich in der Produktebene bei allen selektierten Parts die UserRefProperties (wie Hersteller, Bemerkung, usw..) an.
Problem 1:
Unterhalb dem Parameter Bemerkung würde ich solch ein Auswahlfenster benötigen, wie es Standardmäßig „Source“ vorhanden ist. Name = Bauteilart Auswahl = Type1 ; Type2 ; Type3
Problem 2:
Zusätzlich soll das Makro vom angelegten Parameter „Bestelln. / Fertigmass“ ein Link zu dem als Standart vorhanden Parameter „Definition“ erstellen.
Sprich: Wenn ich bei „Bestelln. / Fertigmass“ einen Eintrag vornehme, soll dieser automatisch bei „Definition“ auch erscheinen.
Bin mit meinem Latein am Ende.
Währe für jede Hilfe herzlich dankbar.
Gruß
Ch.
Hier das Makro:
'// COPYRIGHT DASSAULT SYSTEMES 1999
'//============================================================================
'//
'// Language="VBSCRIPT"
'// Sample of macro to add and valuate attribute for data extraction
'// Author: Jean-Luc MINIER
'// Date : September 7th, 2002
'// Rev. : 01
'//
'//============================================================================
'// It is advised that the user understand the VBScript and VBA concepts before
'// attempting to modify the code to suit their needs. Microsoft Excel 97
'// provides excellent documentation on the use of VBScript and VBA.
'//
'//
'//============================================================================
dim workbooks as AnyObject
dim workbook as AnyObject
dim strWB as Workbench
dim strServ as AnyObject
'//---------------------------------------------------------------------------
'// User customization of the attributes which will be added or valuated
'// tabAttribute is an array which defines the name of the attributes
'// typAttribute is an array which defines the type of the attributes
'// In this sample we provide 4 types but many others are available
'// cf Knowledgeware automation guide
'//---------------------------------------------------------------------------
dim nbAttributes as integer
nbAttributes = 6
dim tabAttributes(6)
dim typAttributes(1)
tabAttributes(1) = "Menge"
tabAttributes(2) = "Bl."
tabAttributes(3) = "DIN / Werkstoff"
tabAttributes(4) = "Bestelln. / Fertigmass"
tabAttributes(5) = "Hersteller"
tabAttributes(6) = "Bemerkung"
typAttributes(1) = "String"
typAttributes(2) = "String"
typAttributes(3) = "String"
typAttributes(4) = "String"
typAttributes(5) = "String"
typAttributes(6) = "String"
'//---------------------------------------------------------------------------
'// Create parameters value
'//---------------------------------------------------------------------------
Sub CreateParameters(iProduct)
On Error Resume Next
dim parameters as Parameters
dim userParameters as Parameters
dim param as Parameter
dim paramName as string
dim RefProduct as Product
set RefProduct = iProduct.ReferenceProduct
set parameters = iProduct.ReferenceProduct.Parameters
set userParameters = iProduct.ReferenceProduct.UserRefProperties
dim nbParameters As Integer
nbParameters = RefParameters.Count
dim sInstanceName As String
dim sPartNumber As String
sInstanceName = iProduct.Name
sPartNumber = iProduct.ReferenceProduct.Name
Err.Clear
dim lfound as Boolean
dim i As Integer
if (nbAttributes > 0) then
for i = 1 to nbAttributes
Err.Clear
paramName = sPartNumber & "\Properties\" & tabAttributes(i)
'// We find if the attribute already exist
lfound = false
for j = 1 To userParameters.Count
if (userParameters.Item(j).Name = paramName) then
set param = userParameters.Item(j)
lfound = true
end if
next
if (lfound = true) then
'// Update of the attribute value if needed
'// In this sample we modify the value using param.Value
if (typAttributes(i) = "String") then
Elseif (typAttributes(i) = "Length") then
Elseif (typAttributes(i) = "Real") then
Elseif (typAttributes(i) = "Integer") then
end if
else
'// Creation of the attributes according to its type
'// If you need to create other type of attribute
'// you can use the mode Record to record a macro interactively and edit it to see the
'// synthax to be used.
if (typAttributes(i) = "String") then
set param = userParameters.CreateString(tabAttributes(i), ".")
end if
end if
Next
end if
End Sub
'//---------------------------------------------------------------------------
'// Main
'//---------------------------------------------------------------------------
Sub CATMain()
On Error Resume Next
dim ActiveDoc As Document
Set ActiveDoc = CATIA.ActiveDocument
'// Check that the active document is a CATProduct
If (InStr(ActiveDoc.Name,".CATProduct")) <> 0 Then
dim product As Product
dim selectedElts As Selection
'// Read the selection defined for instance using the Edit/Search/General with the following options
'// Workbench = Assembly Design & Type = Part
'// ==> All the Products will be selected
set selectedElts = ActiveDoc.Selection
selectedElts.Search("Product,all")
dim number, i, ind As Integer
'// Number of selected Products
number = SelectedElts.Count
msgbox "Nb selected elements: " & Cstr(number)
'// Initialize the first line of data
For i=1 To number
set product = SelectedElts.FindObject("CATIAProduct")
CreateParameters product
Next
End If
msgbox "The End"
End Sub
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP