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!


相关文章
|
缓存 PyTorch 数据处理
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
1689 0
基于Pytorch的PyTorch Geometric(PYG)库构造个人数据集
|
9月前
|
缓存 API 网络安全
告别 Token 贵焦虑!保姆级教程;OpenClaw 阿里云+本地部署,付费/免费模型调教省 Token 成本指南
使用OpenClaw时,Token消耗过高是很多用户的核心痛点——收费模型效果好但成本高,免费模型成本低却能力有限。其实通过“收费模型调教+免费模型执行”的组合玩法,就能实现“Token自由”:先用收费模型打磨成熟任务流程并生成本地脚本,再切换到免费模型执行重复任务,既保证效果又节省成本,真正让免费Token玩出收费API的体验。
6823 1
|
6月前
|
人工智能 数据可视化 测试技术
【教程】阿里云轻量云服务器一键配置OpenClaw
如果你还没有部署自己的 OpenClaw,还可以通过购买腾讯的轻量云服务器,一键秒级部署指南一键秒级部署指南,一键即可在几秒内完成部署。
583 9
|
7月前
|
JSON 安全 API
API数据格式认证方式框架及工具
本文详解API安全三大认证方式:轻量级API Key、无状态JWT令牌及金融级HMAC签名,配Python实战代码与最佳实践(如密钥管理、短期过期、防重放等),助开发者按场景选型,筑牢数据交互防线。(239字)
464 5
阿里云百炼API-KEY在哪查看?百炼api调用方法整理
阿里云百炼API-KEY在哪查看?本文手把手教你从开通平台到获取API-KEY全过程。登录百炼平台,点击免费体验,同意协议后,在控制台右上角头像处进入API-KEY管理,创建并复制密钥,还可领取最高5000万Tokens免费额度,有效期180天。新手必看!
6006 8
|
存储 人工智能 数据可视化
阿里云向量引擎快速搭建企业级RAG最佳实践
本文介绍了基于阿里云搭建RAG(检索增强生成)应用的技术分享。首先回顾了RAG技术背景及其面临的挑战,如大模型幻觉、知识局限和数据安全问题。接着详细讲解了阿里云提供的RAG技术架构,涵盖数据处理、模型服务和高性能检索引擎等多方面能力。最后,通过自研引擎与开源组件的结合,展示了如何快速构建RAG应用,并提供端到端的最佳实践方案,确保系统在企业级应用中的高效性和成本优化。
|
JavaScript 前端开发
Node.js 中实现多任务下载的并发控制策略
Node.js 中实现多任务下载的并发控制策略
723 15