修改计数代码以独立于CATIA中的子程序运行 [英] Modifying a count code to run independently from a sub in CATIA
问题描述
我正在修改很多现有的代码,在尝试了这些代码之后,我对VBA的了解让我望而却步。我的编码经验主要是在Python中,我很难理解对象结构以及VBA中可接受和不可接受的对象。
I'm working on modifying a lot of existing code and after attempting to go through it, I'm way in over my head from what I know about VBA. My coding experience is primarily in Python and I'm having difficulty wrapping my head around the object structure and what is and isn't acceptable in VBA.
我正在尝试在用户选择的给定项目上修改用户添加的属性(属性菜单下的添加其他属性)。此代码作为一个独立的代码可以满足我的要求,但是将其集成到现有代码中却很难。如何将以下代码修改为可以使用的代码,而不必将其包含在自己的子代码中?
I'm attempting to modify user added properties (Add Additional Properties under the Properties menu) on a given item that is chosen by the user. This code, as a stand alone will do what I'm looking for, integrating it into my existing code is proving difficult though. How do I modify the following code to being something that I can use so that it doesn't have to be in it's own sub?
Sub CATMain()
GetNextNode CATIA.ActiveDocument.Product
End Sub
Sub GetNextNode(oCurrentProduct As Product)
Dim oCurrentTreeNode As Product
Dim i As Integer
' Loop through every tree node for the current product
For i = 1 To oCurrentProduct.Products.Count
Set oCurrentTreeNode = oCurrentProduct.Products.Item(i)
' Determine if the current node is a part, product or component
If IsPart(oCurrentTreeNode) = True Then
MsgBox oCurrentTreeNode.PartNumber & " is a part"
ElseIf IsProduct(oCurrentTreeNode) = True Then
MsgBox oCurrentTreeNode.PartNumber & " is a product" & i
Else
MsgBox oCurrentTreeNode.PartNumber & " is a component"
End If
' if sub-nodes exist below the current tree node, call the sub recursively
If oCurrentTreeNode.Products.Count > 0 Then
GetNextNode oCurrentTreeNode
End If
If oCurrentTreeNode.Products.Count = 0 Then
oCurrentTreeNode.ReferenceProduct.UserRefProperties.Item(1).Value = "Yippee!!!!!"
End If
Next
End Sub
到目前为止,这是我的尝试,当我将其放入当前文本时,它似乎被忽略了。该计划将取代我们修改现有属性的当前方式,以便能够读取CATIA树并修改单个零件和产品。另外,我尝试添加一个createstring来为不存在的用户属性创建一个新的用户属性。这将返回一条错误消息,说明程序期望a =。
This is my attempt so far and it appears to get ignored when I put it into our current text. The plan is to replace the current way we modify the existing properties so that it's able to read through CATIA trees and modify individual parts and products. Additionally, I attempted to add a createstring to make a new user property for one that is not there. This returns an error saying that the program is expecting a =. Any help is greatly appreciated.
Dim oCurrentProduct As Product
Dim oCurrentTreeNode As Product
Dim i As Integer
' Loop through every tree node for the current product
For i = 1 To oCurrentProduct.Products.Count
Set oCurrentTreeNode = oCurrentProduct.Products.Item(i)
' Determine if the current node is a part, product or component
If IsPart(oCurrentTreeNode) = True Then
MsgBox oCurrentTreeNode.PartNumber & " is a part"
ElseIf IsProduct(oCurrentTreeNode) = True Then
MsgBox oCurrentTreeNode.PartNumber & " is a product" & i
Else
MsgBox oCurrentTreeNode.PartNumber & " is a component"
End If
' if sub-nodes exist below the current tree node, call the sub recursively
If oCurrentTreeNode.Products.Count > 0 Then
GetNextNode oCurrentTreeNode
End If
If oCurrentTreeNode.Products.Count = 0 Then
oCurrentTreeNode.ReferenceProduct.UserRefProperties.Item(1).Value = "Yippee!!!!!"
oCurrentTreeNode.ReferenceProduct.UserRefProperties.CreateString(Value, "Input")
End If
Next
推荐答案
看起来像CreateString返回一个属性对象。尝试像这样使用它:
Looks like CreateString returns a property object. Try using it like this:
' Use this line where you want to make a new property
SetUserProperty oCurrentTreeNode.ReferenceProduct, "Input", "Yippee!!!!!"
Public Sub SetUserProperty(ByVal myProduct As Product, ByVal code as String, ByVal newValue as String)
Dim myUserProperties As Object 'As Parameters
Dim myUserProperty As StrParam
Set myUserProperties = myProduct.UserRefProperties
Set myUserProperty = myUserProperties.CreateString(code, "")
myUserProperty.ValuateFromString newValue
End Sub
这篇关于修改计数代码以独立于CATIA中的子程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!