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!

specify a part in product 1

Status
Not open for further replies.

nothingid

Mechanical
Oct 11, 2014
19
TW
hi,
I have problem coding the catvba below

Code:
Dim oDocument As Document
Set oDocument = CATIA.ActiveDocument
 
Dim oProduct As Product
Set oProduct = oDocument.Product

Dim oPart As Part
Set oPart = oProduct.Part

Dim oPoint As Point
Set oPoint = oPart.FindObjectByName(Name)

so,how to fix this problem?
it seems that oProduct.Part goes wrong,
neither oDocument.Part can work

anyone has solution to this?
please help!

thanks
 
Replies continue below

Recommended for you

but what's the point?
now I try to focus on just a part of a product, but catia shows that the line "Set oPart = oProduct.Part" is worng

I don't know if the code behind the line will be the cause of error,
I don't think so, thus I didn't post it here. does it matter?

anyway, I'll try to make this clear
originally I just open a CATpart, and the code was
Code:
Dim oDocument As Document
Set oDocument = CATIA.ActiveDocument
 
Dim oPart As Part
Set oPart = oDocument.Part

Dim oPoint As Point
Set oPoint = oPart.FindObjectByName(Name)
.
.
.

it works,
and then I open a CATproduct containing the part in it,
so I made a change to the code,
I just can't figure out why..
maybe I should code another way, but how?
how to fix it if I open a CATproduct?
 
Depending on what you want to do there are different approaches....you can search in your product the part you wish and "focus" on that by using search by name query.

I'm always trying to find what designers want at the end because this can give you a much more clear idea how to approach the problem.

Regards
Fernando

 
so you means that

Code:
Set oPart = oProduct.Search("Name='Part1',all")

is that right or..?
sorry I know little about the language
can you just give me an example or briefly explain how to use this function?


and, I really want to know why can't I type like "Set oPart =oProduct.Part" ?
 
Using Search function of this forum you will find for example


and many other threads which can guide you. And check also the v5automation.chm file in your CATIA installation folder.

Regards
Fernando

 
Ferdo is asking what you want to do and what conditions you are working in so he can help you. If he guesses, the solution will likely be incorrect.

So it sounds like you want a macro that will work if you have either a Part or Product loaded? Is that correct?

Dim oDocument as Document
Set oDocument = CATIA.ActiveDocument
Dim oPart as Part
Dim oProduct as Product

If uCase(TypeName(oDocument)) = "PARTDOCUMENT" Then
Set oPart = oDocument.Part​
Else if uCase(typename(oDocument)) = "PRODUCTDOCUMENT" Then
Set oProduct as oDocument.Product​
'Are you looking for a certain feature in a specific part or are you looking for a certain feature in all the parts in the assembly?​
Else
Msgbox "Document type not supported by this macro" & vbCrLf & "Exiting Macro", vbCritical​
Exit Sub​
End if
 
thank you
actually it's a module, not macro, I think they are a little different
and I only need to deal with the CATProduct, so 'if...then...' is not necessary


in a specific part, I want to modify the points in a geometry set in it, by FindObjectByName function
by the way, I can't use select command since I want the whole thing to be done automatically

 
In fact you need to handle a specific Geometrical Set and not the CATProduct...and then some specific points and not all of them (if I remind well from your older thread).

Best way is when you create them first time, give them specific names, do not let CATIA to name them automatically, in order to search and modify them later on after the name.

And sometimes if-then is it necessary just to prevent user to use the catscript/cavbs/catvba/hta/MSOffice/chm/exe or what ever in the wrong CATIA module. This is a very good practice of programmers, not all users are very careful/interested where they are using macros and then they will ask you why is not working. I have to say that this is a weak point for me, I'm not doing always this and then I have to explain why is not working the macro....

I really like when users like lardman or Alexlozoya or itsmyjob (and many others) are trying to explain why they are programming how you can see here in the forum, I'm learning always something from them (I'm not a professional programmer).

Regards
Fernando

 
now I decide to execute two macros to complete the task...a little bit tiring but much easier since I don't need to care about the syntax of part,product,document...
and I create an icon of Module1, put it in the macro

Code:
CATIA.StartCommand("Module1")

everything goes well when I execute the macro manually in CATIA,
but to my surprise, it gives an error message when I execute the file in a batch mode...
========================
Power input message

Unknown command:Module1
========================
why?
I have tried other command in the macro ,so I am sure that the problem is caused by module
but why? I have created an icon for the module, also I can input "c:Module1" in the command line below,

the problem is : how to open catia files in batch mode and execute the macros and modules?

is it a wrong way to use startcommand("Module1") in the macro when performing the task in batch mode?


 
finally....it's done
I use 'CATIA.SystemService.ExecuteScript' in my macro to call a module

thanks anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top