0

I've hit a snag, I've been on this for a week now and continue to get to the same problem. I'm using CATIA V5R26 and I'm attempting to change user defined properties (Define Other Properties) through selecting a product/part in CATIA and running a macro.

Currently, this is what I have

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 = "Yeet"

This yields 2 problems, I still am unable to change level 2 or further attributes. This only works on the top level. Additionally, there are 11 user defined properties I'm attempting to manipulate and the code will only do 3. I've tried a lot of different routes and also used other peoples code that they use and for some reason it doesn't work.

What needs to be done to allow this to work on multiple levels? Why would this only be able to change 3 of the 11 user defined properties?

aaron
  • 81
  • 1
  • 10
  • Wish I could help, sounds interesting. Maybe info found here could help? https://stackoverflow.com/questions/47574338/catia-v5-vba-custom-bom-macro-inserting-userrefproperties-into-table – ionizing Apr 27 '20 at 18:30
  • This must be just a snippet. I don't see `Option Explicit` or any subs. I recommend using objects and `With` blocks to shorten your references. You have too many dots `.` – HackSlash Apr 27 '20 at 19:14
  • Very small snippet, the total code is about 4,500 lines.... I'm updating it so it doesn't point just directly at a very specific name and trying to convert it to "generalize" and be able to update the entries in "Define Other Properties" on any object that is selected. – aaron Apr 27 '20 at 19:46
  • Ok, break this one action out in to a function and then post the full function. One step at a time, you know. – HackSlash Apr 27 '20 at 19:52
  • I'll post another post in a second, I can only post so much given I'm under an NDA. – aaron Apr 27 '20 at 19:54
  • Is there a way to open a direct chat? Code is too long even for snippets. – aaron Apr 27 '20 at 20:04
  • Ok, so there's 3 that aren't working and 2 of them I think I know why and it's because they're tied to code elsewhere. The third one that isn't is a radio button that either YES or NO. It is driven by a userform and the only thing that it is changing is the input value. – aaron Apr 27 '20 at 20:25

1 Answers1

1

One problem is that you are basing this off of a selection. If the user selects the wrong type of object it's going to throw an error.

That said, try this:

Set Pull_document2 = CATIA.ActiveDocument.Selection
Set ProducRef = Pull_document2.Item(1).LeafProduct.ReferenceProduct
With ProducRef.UserRefProperties
    .Item("DESIGNER").Value = "Yeet"  ' This is how I think it should work
    .Item(.Name & "\Properties\DESIGNER").Value = "Yeet"  ' This is based on the code you had
End With

Inside that With block you should be able to list out all the properties you want to change.

HackSlash
  • 4,944
  • 2
  • 18
  • 44
  • That, it works almost. It will do 7 out of 11 of the properties. I'm pretty stunned right now cause I've tried that same structure as one long text over and over again and it never did this.... – aaron Apr 27 '20 at 19:40
  • It's possible that you have the name of the property wrong, or the property is read-only. You can use a do-loop to print out the name of every property so you can see the actual names. Once you have verified the names then you can look in the manual to see if the remaining properties are read only. – HackSlash Apr 27 '20 at 20:24
  • I'm a rookie when it comes to VBA in CATIA. Would this do loop be written as CATIA.ActiveDocument.Selection.Item(i).Value.Name?? – aaron Apr 27 '20 at 20:31
  • Sorry, I should write the whole thought out. ' while i – aaron Apr 27 '20 at 20:39
  • there is no name of value. It would be just name. Read this: http://www.coe.org/p/fo/et/thread=15608 – HackSlash Apr 27 '20 at 20:39
  • Ok, i'll take a look at it when I get back to work tomorrow. Is there any suggestion you would have for making this operate on level 2 or greater in the product tree? – aaron Apr 27 '20 at 20:41
  • Each level has it's own set of rules. Only the documentation can tell you what you need to know. Read the API for that part of the tree – HackSlash Apr 27 '20 at 21:06
  • Is it possible to navigate a tree using selection? Like, say I have product1 ---> product2 ----> product3, which could have different names depending on the user. Is it possible to have it run the code you gave me run based on what part or product the user selects? Am I reading it right that the code in the link you gave me could be modified to do this task? – aaron Apr 27 '20 at 21:28
  • Yeah, you need code that verifies the selection and notifies the user if the selection is invalid. I think this question is better suited to a forum like the COE forum. StackOverflow is for fixing a single problem with your code, not asking how to do something. – HackSlash Apr 27 '20 at 21:30
  • ok, I read the link you sent me and it appears that the information to do so is in there. I'll need to compile everything you gave me and process it so that I can put a well thought out question on COE. Thanks for your help! – aaron Apr 27 '20 at 21:32
  • I read through the link you gave me and this will do exactly what I've been attempting to do. The integration is struggling though, as a stand alone macro it works. When I drop the subs as Calls, the code seems to ignore them. Is there a reason for this? – aaron Apr 28 '20 at 15:11
  • Please open a new question. Show the full procedure and a snip that shows all the variables used in the procedure call. These are comments on an answer. – HackSlash Apr 28 '20 at 15:27
  • Done. https://stackoverflow.com/questions/61484776/modifying-a-count-code-to-run-independently-from-a-sub-in-catia – aaron Apr 28 '20 at 16:10