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!


相关文章
|
6月前
|
Linux 测试技术
Linux基础项目开发1:量产工具——文字系统(四)
Linux基础项目开发1:量产工具——文字系统(四)
67 0
Linux基础项目开发1:量产工具——文字系统(四)
|
1月前
|
移动开发 数据可视化 小程序
DIY可视化软件环境准备
DIY可视化软件环境准备
30 0
|
6月前
|
小程序 数据安全/隐私保护
基于小程序的校园二手交易系统设计与实现(源码+lw+部署文档+讲解等)
基于小程序的校园二手交易系统设计与实现(源码+lw+部署文档+讲解等)
281 0
|
Rust Java 测试技术
软件代码与质量管理(更新版)(二)
软件代码与质量管理(更新版)(二)
149 0
软件代码与质量管理(更新版)(二)
|
Devops 开发工具 git
软件代码与质量管理(更新版)(一)
软件代码与质量管理(更新版)(一)
134 0
|
消息中间件 分布式计算 NoSQL
如何了解一个软件的设计?
刚入职,接手新项目,面对一个全新项目,怎么快速研究它? 很多人直接看源码,一头扎入代码,很快就迷失其中,最初那股子探索精神,也会逐渐被迷茫所替。有多少次你满怀激情打开一个开源项目,结果多半坚持不了就放弃。问题出在哪?迷茫是因为缺少对软件整体了解,如同不带地图指南针就闯入热带雨林,迷路只是早晚。阅读源码是必经一步,却不是第一步。应先从了解软件设计开始。
132 0
|
自然语言处理 API
CATIA二次开发—参数那点事
CATIA二次开发—参数那点事
CATIA二次开发—参数那点事
|
移动开发 数据可视化 搜索推荐
MindManager2023软件功能特色介绍
MindManager思维导图软件是一款创造、管理和交流思想的思维导图软件,界面友好功能强大,头脑风暴、会议管理及项目管理工具帮您轻松创建思维导图,有序组织思维、资源和项目进程。
776 0
|
JavaScript 芯片
硬件开发笔记(二):硬件开发基本流程,制作一个USB转RS232的模块(一):开发基本过程和元器件选型
硬件开发笔记(二):硬件开发基本流程,制作一个USB转RS232的模块(一):开发基本过程和元器件选型
硬件开发笔记(二):硬件开发基本流程,制作一个USB转RS232的模块(一):开发基本过程和元器件选型
|
BI 数据安全/隐私保护

相关实验场景

更多