我想创建一个新产品,然后在两个小时后,将其他零件从另一个文档添加到新产品Doc,这似乎是不可能的



看来我只是无法添加一个复制的第二部分A ProductDoc。可以将其直接粘贴到productDocument中,但我无法保存它。我需要做的是:

  1. 创建ProductDoc
  2. 在rootproductDoc中创建productDoc
  3. 从另一个文档复制部分
  4. 第二步中的productDoc粘贴部分

有人想知道该怎么做?

IM使用Catia V5-6版本2016,ServicePack 5构建编号26

似乎没有任何功能可以从步骤2中选择productDoc。

我弄清楚了,谢谢下降。

您不能将partDocument本身添加到产品中,它需要是添加零件的产品图(使用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", "")

maxvr,感谢您回来并发布解决方案!这对于我正在研究的产品对称宏确实有帮助。如果零件已经存在,还有另一种方法可以将零件插入catprouduct。

'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

相关内容

  • 没有找到相关文章