似乎我只是无法将复制的第二部分添加到productDoc中。可以将其直接粘贴到ProductDocument中,但是我无法保存它。我需要做的是:
有人知道该怎么做吗?
我正在使用CATIA V5-6版本2016,ServicePack 5内部版本26
似乎没有任何功能可以从步骤2中选择ProductDoc。
答案 0 :(得分:0)
MaxVR,感谢您回来发布解决方案!这对我正在研究的产品对称宏真的很有帮助。如果零件已经存在,还有另一种方法可以将零件插入到 CATProduct 中。
'These three lines are variants
'products_variant_file_open represents the product that we want our part to be added to
'variant_array_file_open is where we store our file path
Dim products_variant_file_open
Set products_variant_file_open = current_rh_product.Products
Dim variant_array_file_open(0)
variant_array_file_open(0) = root_file_location & "\" & current_product.PartNumber & "_RH.CATPart"
'Below is the command that inserts the CATPart. The left thing to specify is the array that holds
'the file name and the right thing is the type of file to add
以下是一些示例代码,展示了我如何获取文件路径以从中插入零件
'prod_doc.Path gets path of the product document and the stuff to the right becomes the folder name
root_file_location = prod_doc.Path & "\" & name_prod.Name & "_RH_Parts"
Dim fso As FileSystemObject
Set fso = New FileSystemObject
'Creates a folder in specified path with the specified name
fso.CreateFolder (root_file_location)
然后我使用了一个函数来遍历文件夹并搜索特定名称
Function rh_folder_lookup(rh_part_file_name As String,
root_file_location_func As String)
'Default rh folder lookup to be false when it's false we can't find a matching file in our folder so we make a new rh part
rh_folder_lookup = False
'Set the file name to all the files in our folder
Dim fileName As Variant
fileName = Dir(root_file_location_func & "\") 'The slash at the ends makes the directory all the files in the folder instead of just that folder
'Loop through all files in a folder
While fileName <> ""
If fileName = rh_part_file_name & ".CATPart" Or fileName = rh_part_file_name Then
'MsgBox fileName & "!!!"
rh_folder_lookup = True
Exit Function
End If
fileName = Dir 'Set the fileName to the next file
Wend 'Wend means end when the condition is true
End Function
答案 1 :(得分:-1)
我想通了,谢谢那些下注者。
您不能将PartDocument本身添加到产品中,它必须是要添加零件的ProductDocument(带有AddNewComponent(“ Part”,“”))。
Dim documents1 As Documents
Set documents1 = CATIA.Documents
Dim productDoc As ProductDocument
Set productDoc = documents1.Add("Product")
Dim rootProduct As Product
Set rootProduct = productDoc.Product
Dim childProduct As Product
Set childProduct = rootProduct.Products.AddNewComponent("Product", "")
Dim part1 As Product
Set part1 = childProduct.Products.AddNewComponent("Part", "")
Dim part2 As Product
Set part2 = childProduct.Products.AddNewComponent("Part", "")