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!


相关文章
|
Web App开发 JavaScript 前端开发
2023Node.js零基础教程(小白友好型),nodejs新手到高手,(一)NodeJS入门
2023Node.js零基础教程(小白友好型),nodejs新手到高手,(一)NodeJS入门
1017 0
|
前端开发 Java 关系型数据库
【Mybatis-Plus】mybatisplus更新时,实体字段为空,数据库不更新的解决方案
【Mybatis-Plus】mybatisplus更新时,实体字段为空,数据库不更新的解决方案
1775 0
|
开发者
STM32中断详解及其编程实践
STM32中断详解及其编程实践
1027 1
|
前端开发 JavaScript 开发者
React 按钮组件 Button
本文介绍了 React 中按钮组件的基础概念,包括基本的 `<button>` 元素和自定义组件。详细探讨了事件处理、参数传递、状态管理、样式设置和可访问性优化等常见问题及其解决方案,并提供了代码示例。帮助开发者避免易错点,提升按钮组件的使用体验。
715 77
|
关系型数据库 MySQL 数据库
mysql查看用户的过期时间
通过本文的介绍,希望您能够深入理解和掌握在MySQL中查看用户过期时间的方法,并在实际项目中灵活运用这些技术,提升数据库管理的安全性和效率。
1200 3
|
Windows
【错误记录】Windows 控制台程序编译报错 ( WINDOWS.H already included. MFC apps must not #include <Windows.h> )
【错误记录】Windows 控制台程序编译报错 ( WINDOWS.H already included. MFC apps must not #include <Windows.h> )
1393 0
【错误记录】Windows 控制台程序编译报错 ( WINDOWS.H already included. MFC apps must not #include <Windows.h> )
|
机器学习/深度学习 人工智能 算法
目标检测技术研究现状及发展趋势
随着人工智能、深度学习技术的快速发展,受到深度学习在自然场景图像目标检测中的成功应用的影响,许多学者尝试将深度学习方法应用于图像的目标检测中,基于卷积神经网络的目标检测成为发展趋势。
2301 0
目标检测技术研究现状及发展趋势
|
监控 编译器 C++
【代码讲解】【C/C++】获取文件最后修改的时间(系统时间)
【代码讲解】【C/C++】获取文件最后修改的时间(系统时间)
957 0