CATIA V6 二次开发—获取非激活产品/零件(QA)

简介: CATIA V6 二次开发—获取非激活产品/零件(QA)

Q(cao bingyong):


Hi, I am new in V6 COM development, and recently encountered a problem of getting the GeoSet from another part (not in active) which is in another product. I can use the following code to get the root product , but have no idea to find the child product of the root one by name, not to mention, to find the part inside. So, can anyone help? Thanks a lot!

pLMProductService.EditedContent.Item(1)

A(Mahefa Ralijaona):

Hello,
There are I think several ways to do this. Here is one of them: not necessarily the fastest or the simplest, but it's one way. Hope it helps.
Sub CATMain()
    ' Getting active editor (the current tab)
    Dim oActiveEditor As Editor
    Set oActiveEditor = CATIA.ActiveEditor
    ' Getting the root occurrence of the editor
    Dim vpmRootOcc As VPMRootOccurrence
    Set vpmRootOcc = oActiveEditor.GetService("PLMProductService").RootOccurrence
    ' Getting all its children
    Dim vpmRootChildrenOcc As VPMOccurrences
    Set vpmRootChildrenOcc = vpmRootOcc.Occurrences
    ' Getting the first one (28629.1 in your case)
    Dim vpmRootChild1Occ As VPMOccurrence
    Set vpmRootChild1Occ = vpmRootChildrenOcc.Item(1)
    ' Getting the first part inside your 28629.1 (instance 28628.2 of the 3DPart in your case)
    Dim vpmPart1Occ As VPMOccurrence
    Set vpmPart1Occ = vpmRootChild1Occ.Occurrences.Item(1)
    ' Getting the part instance, then the reference
    Dim vpminstPart As VPMInstance
    Set vpminstPart = vpmPart1Occ.InstanceOccurrenceOf
    Dim vpmrefPart As VPMReference
    Set vpmrefPart = vpminstPart.ReferenceInstanceOf
    ' Getting the 3DShape instance, then the 3DShape reference
    Dim vpmrepinstPart As VPMRepInstance
    Set vpmrepinstPart = vpmrefPart.RepInstances.Item(1)
    Dim vpmreprefPart As VPMRepReference
    Set vpmreprefPart = vpmrepinstPart.ReferenceInstanceOf
    ' Getting the part item from the part(i.e. so far the 3DShape is a PLM object, we need to get to the object allowing to access the internal features of that PLM object)
    Dim oPart As Part
    Set oPart = vpmreprefPart.GetItem("Part")
    ' Getting the geometrical sets
    Dim oHybridBodies As HybridBodies
    Set oHybridBodies = oPart.HybridBodies
    ' Getting the first one
    Dim oGeoSet1 As HybridBody
    Set oGeoSet1 = oHybridBodies.Item(1)
    ' Check
    MsgBox oGeoSet1.Name
End Sub

Q(cao bingyong):


It works! Thanks very much. In addition, my objective is to find the shape in the unactive Part, and use it in my active Part to go on my geo operation. When I use it in a direct way, it goes wrong, and is it necessary to copy and paste(as result) the shape to my active Part before I do the following geo operation? Hope for your reply. Thanks again for your help!

 // CurrentPart is the active Part
 HybridShapeFactory hsf = (HybridShapeFactory)CurrentPart.HybridShapeFactory;
 // line1 and line2 are shapes I got from the unactive Part
 var point1 = hsf.AddNewPointOnCurveFromPercent((Reference)line1, 0.5,false);
 var point2 = hsf.AddNewPointOnCurveFromPercent((Reference)line2, 0.5, false);
 var line3 = hsf.AddNewLinePtPt((Reference)point1, (Reference)point2);
 CurrentPart.HybridBodies.Item(1).AppendHybridShape(line3);
 CurrentPart.Update();

A(Mahefa Ralijaona):

Yes, might be necessary to do so (copy paste “As Result” or “With Link”, or …). I’m not 100% sure but I think you won’t be able to do anything in your active part by directly pointing to an element that is outside. Unless maybe check your Preferences? In your Preferences, make sure that when you are using an object that is outside, you keep a link to the selected object (see picture attached).


20210118093126666.png

Q(cao bingyong):

Thanks for your reply! I have checked my preferences, and the button in the picture has already been selected. Maybe it is essential to copy and paste the object outside when using the automation.


Thank you again, and good luck to you!


相关文章
|
29天前
|
内存技术
【软件开发流程控制文档】嵌入式应用软件在线升级功能软件概要设计
【软件开发流程控制文档】嵌入式应用软件在线升级功能软件概要设计
29 0
|
4月前
|
JavaScript Java 测试技术
基于微信小程序的汽车维修管理系统的设计与实现(源码+lw+部署文档+讲解等)
基于微信小程序的汽车维修管理系统的设计与实现(源码+lw+部署文档+讲解等)
|
4月前
|
关系型数据库 数据库 数据安全/隐私保护
已知日程表软件用户手册
已知日程表软件用户手册
|
监控 算法
转:为什么说文档管理软件中应用弗洛伊德算法是更加有效的
弗洛伊德算法(Floyd算法)是一种用于寻找加权图中最短路径的算法。在文档管理软件中,可以使用弗洛伊德算法来帮助优化路线规划或者监控摄像头的布局。
82 0
|
API C# C++
CATIA二次开发—漫谈开发环境
CATIA二次开发—漫谈开发环境
CATIA二次开发—漫谈开发环境
|
搜索推荐
小众软件大盘点,这5款软件你一定要试一下!
你是否喜欢一些小众且无广告的软件?如果是的话,我这边有一些给你推荐的。
113 0
小众软件大盘点,这5款软件你一定要试一下!
|
自然语言处理 API
CATIA二次开发—参数那点事
CATIA二次开发—参数那点事
CATIA二次开发—参数那点事
|
Android开发 计算机视觉
泼辣修图2023软件最新版功能介绍
无论你是入门新手还是摄影专家,泼辣修图都可以满足你的一切需求。对于入门新手而言,泼辣修图搭载的先进自动增强工具和富有创意的图像滤镜,可以帮助他们快速雕琢图像的每一个细节。对于摄影专家而言,图层混合、局部调整、曲线工具等等功能则是他们青睐有加的专业特性。泼辣修图专业版是一款强大的专业修图软件,拥有上百款调色工具还有丰富的图层素材, 更有智能的人像修饰面板,具备物体识别的智能蒙板,高效的滤镜管理系统和强大的文字
223 0
|
BI 数据安全/隐私保护