Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with selection under macro

Status
Not open for further replies.

TiagoFigueiredo

Industrial
May 22, 2013
494
PT
I'm having a problem with selection, under macro execution.

I have a product which contains another products and that products contains parts.

I need to select the parts under the 2nd product.
1_xv7ddz.png



I have wrote the following macro (just the part of selection)
Code:
  For i = 1 To Num_axis
                Dim comps As Integer
                Product2 = Product1.Products.Item(Number_parts + i - 1)
             
                comps = Product2.Products.Count

                For c = 1 To comps
                    selection1.Add(Product2.Products.Item(c))

                Next
            Next

when the macro runs, looks good, but i can't see the selection on catia.Only we can see that there are something selected, because CATIA say that there are a few elements selected.
2_ihn9wl.png


Like I can't see what is selected, and for debuging, I have resquested a message box, with the name of the selected elements. that message box returns me the part name of each part. It looked really good, So far so good.

But the next action is within each part find a body with a specific name, and copy and past it to another part. And here is the big problem. the body is not pasted in the same place of it's part location. Is pasted in the coordinates, where was drawn on original part. Ex: the part in assembly is located at coordinates 1000,1000,1000 and the body that i need to copy is drawn on 0,0,0, when i copy it in assembly it will appear on other part on location 0,0,0, not on 1000,1000,1000. it looks like i have opened the part with body, then open the other part and make a paste, not making the use of the in context location...

So trying to debug the code, I have removed the code of parts selection (the code that I have posted before), and stop the code at this point. After this I make the selection with mouse clicks, and resume the code. And like this it works really fine. So I assume that there is some problem with the selection of the parts with code.

Any idea?



Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Replies continue below

Recommended for you

I love my UNknowledge of programming, I really don't know to control things like a real programmer.

Apparently the problem is solved. When I inserted the variable to product1 (which contains the product), I inserted a new variable.

product1 = selection1.Item(1).Value
My_Product = selection1.Item(1).Value

Exactly the same way that product1 is attributed it's value.

On the code of the previous post i switched from product1 to My_Product, and voilá it works!!!! Definitly I hate computors, because they are above my intelligence level. It must be a reason for this don't work properly, but i don't understand it.


Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
you learn.. you're on the good track.

I've been thru some (stupid) stuff myself during my learning phase (which is not finished yet)

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top