0

I'm looking to call user referenced properties in CATIA. Currently I am able to do this through a direct path using:

xyz = CATIA.Activedocument.product.UserRefProperties.Item("DESIGNER").Value
MsgBox (xyz),0

I'm looking to generalize so that what ever the user is selecting in the window, that information will be displayed. I'm able to do something similar to what my goal is using code like this:

abc = CATIA.ActiveDocument.Selection.Item(1).Value.Name
MsgBox (abc),0

This gets to my issue. The above code will call system defined properties based on selection, however, this will not work on the user defined properties.

How can I modify this code to take the information stored in a user defined property and display it?

Zzirconium
  • 431
  • 1
  • 10
  • 32
aaron
  • 81
  • 1
  • 10

1 Answers1

0

You might have a problem due to the fact that starting at level 2 substructure, your selection does not hold a Reference, but an instance, try this code (I display the 1st User Added Property of the selected product)

MsgBox CATIA.ActiveDocument.Selection.Item(1).LeafProduct.ReferenceProduct.UserRefProperties.Item(1).ValueAsString
Zzirconium
  • 431
  • 1
  • 10
  • 32
  • You're onto something, it does seem that the file is storing an instance. When I tried that for writing to the properties I want, nothing happened. What causing the mishap? – aaron Apr 24 '20 at 16:18
  • it is another problem than your original question. You should create another one or edit it. By the way, the write permission on products depends on many factors. What kind of parameter do you have ? String, or dimensioned ones (like length, mass, etc.) ? – Zzirconium Apr 27 '20 at 09:55
  • It's a string for all the inputs. – aaron Apr 27 '20 at 13:21
  • It works on my test data : Item(1).Value="foo". Can you give me the code you use to write the calue. And also add a screenshot of you product structure tree in you original question (just Paste the image it will upload it to imgur and porpose you to add it in SO) – Zzirconium Apr 27 '20 at 13:29
  • I tried the code you gave me and it just gets ignored by the system. I modified it too and attempted to input direct fields and it still gets ignored..... I honestly don't know why but it seems that my code is ignored constantly and chooses to only work some of the times. Assigning DoEvents doesn't change anything. – aaron Apr 27 '20 at 13:29
  • This is what I've been trying to use to write data. 'Dim Pull_document2 As Selection Set Pull_document2 = CATIA.ActiveDocument.Selection Document_Entry = Pull_document2.Item(1) CATIA.Documents.Item(Document_Entry).product.Parameters.Item("\Properties\XYZ").Value = Y1U' This is what I use to call data. 'Set Pull_document2 = CATIA.ActiveDocument.Selection Part_number_name = Pull_document2.Item(1).Value.PartNumber Document_Entry = Part_number_name & ".CATProduct" DESIGNER_INPUT.Text = CATIA.Documents.Item(Document_Entry).product.Parameters.Item("Properties\XYZ").ValueAsString'' – aaron Apr 27 '20 at 13:35
  • Sorry for multiple messages, character limits. The Structure I'm using is just Product 1 ---> Product 2. Nothing special since it's for testing purposes. – aaron Apr 27 '20 at 13:39
  • Again you should add your code attempts and problem by editing your question, with using the {} to format the code sections. Your code seems to make some references to mysterious variables and objects (DESIGNER_INPUT.Text ??) – Zzirconium Apr 27 '20 at 14:48
  • I see, I'm new to this website and will try. None of my code has worked. I'm able to pull and I am very unfamiliar with this program. I think it'll be easier to explain what I'm doing..... User Selects Part/Product User runs our macro, macro pulls up existing information (this works so far) at any level User inputs data for selected part/product in any level. Upon pressing enter, user defined properties are updated. (This is where I am struggling) Code attempt {CATIA.ActiveDocument.Selection.Item(1).product.Parameters.item("DESIGNER").value = inputted Value} – aaron Apr 27 '20 at 15:06
  • I tried your code again and it does work on the top level user defined properties. However on level 2 and 3 it doesn't change anything. {CATIA.ActiveDocument.Selection.Item(1).LeafProduct.ReferenceProduct.UserRefProperties.Item("DESIGNER").Value = "SUCK IT CATIA"} – aaron Apr 27 '20 at 15:15
  • Are you sure your Item("DESIGNER") is working ? Because if the property is called DESIGNER, and let say your product name (reference) is MySubProduct, you must use Item("MySubProduct\Properties\DESIGNER") – Zzirconium Apr 27 '20 at 15:26
  • I see, so with the leaf product I need something to call in the instance still that is selected? – aaron Apr 27 '20 at 15:32
  • yes, you could use something like Item(CATIA.ActiveDocument.Selection.Item(1).LeafProduct.ReferenceProduct.Name + "\Properties\DESIGNER") – Zzirconium Apr 27 '20 at 15:35
  • So... This is what I have. It only changes the top level still. {Dim Pull_document2 As Selection} ..........{Set Pull_document2 = CATIA.ActiveDocument.Selection} ..........{Part_Number_Name = Pull_document2.Item(1).LeafProduct.ReferenceProduct.Name} ............{CATIA.ActiveDocument.Selection.Item(1).LeafProduct.ReferenceProduct.UserRefProperties.Item(Part_Number_Name & "\Properties\DESIGNER").Value = ".....Coding in CATIA sucks"} – aaron Apr 27 '20 at 15:45
  • Also, it seems to run into another problem and this is a problem I was having before. The same string of code, modified only for the property name, only changes 3 out of 11 of the entries. All are designated Strings. All have the same line of code with only the word DESIGNER changing to something such as TITLE. – aaron Apr 27 '20 at 15:55
  • Do you use VBA project for your macro ? Or VB or VBS ? I recommend you use VBA as you will be able to debug your code, and watch variable values realtime (especially regarding the write permissions on parameters, as it might be an issue that explain some works and some does not.) I would recommand you use Item(1), Item(2); Item(3)... instead of the Item(name) version, as it will remove all doubt about the proper Name formatting. You could use a Dictionary to store the Name/Value you want, then loop on the Items of the UserRefProperty and set the dictionary value according to the key – Zzirconium Apr 27 '20 at 22:48
  • I'm using VBA, I never thought about using item(i). This would work well if I can get the product instance to call correctly. – aaron Apr 27 '20 at 23:03