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!

VBA MACROS - GET PART BODY COLOR AND CHANGE IT TO WHITE COLOR, THEN GO BACK TO PREVIOUS COLOR

Status
Not open for further replies.

Thosnow

Aerospace
Feb 23, 2017
68
CA
Hello Ferdo and Others

I have tried so hard to write a VBA macro to get Catia Part Body's color from a part document, change part color to white color and change it back to previous color. I have got to a point below and the error "type mis-match" appeared and I do not know how to fix it since I am novice to Catia macro programming, even I have read lots of online forums and tips.

--------------------------------------
Option Explicit

Sub CATMain()

Dim oDoc As PartDocument
Set oDoc = CATIA.ActiveDocument.Selection

Dim visProperties1 As VisPropertySet

Dim r, g, b
r = CLng(0)
g = CLng(0)
b = CLng(0)

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.GetRealColor r, g, b 'Type mismatch error
MsgBox "r = " & r & " g = " & g & " b = " & b

End Sub

I would really love Ferdo and others to help me out to achieve my objectives above. As well, if you are able to show me how to print out the image of the part in white color and other 3D annotation captures in a Catia part document, then I am so grateful for your help. Please correct the above program in VBA, not CATScript or VB Script.

Thank you All and have a nice weekend.

Quin
 
Replies continue below

Recommended for you

Hello,

Believe me, I'm not the best programmer (by the way, I'm not even a programmer [smile], I'm just a user), there are several users here with much more knowledge in programming then me.

Attached you will find a catvba which is doing just this first part of what you want to do. I simply copied and paste the code from the CATScript to catvba and adapt the code for vba, following the errors indicated.

Please come back with more details if you will have problems continuing to develop the code. If you want to learn coding, it will be good for you to check v5automation.chm file and from time to time to take a look at examples in CATIA_Portable_Script_Center (search the forum also). I'm also a self teaching guy, a way to learn is to do, search and try different things by yourself and after that asking for help (of course, if you don't have the possibilities to get a specific training done by professionals, which in my opinion is best option).

Regards
Fernando

- Romania
- EU
 
Hi Ferdo,

I know you will reply quickly.

As you mentioned in your pos, I do not see you code attached any where. Please re-post it if available.

I have read the V5Automation.chm, copied a few examples from that document to vba, but none of them has worked so far. I have tried so hard to understand and adapt those codes in VBA but obviously not successful yet.

I would really love somebody to help me out.

Thank you All in advance.

Quin
 
Thank you Ferdo,

I run your VBA program in CATIA V5-R2015 and V5-2016 but

1) I did not ask the user for picking a feature or part to get color from
2) As per attached image, part's color would not seem, r = 0, g = 0, b = 0

My objective is that as soon as you run the program, it will automatically access the part body of active document/Catia part, display part's current color, save it to a variable, change current color to white, and change white color back to its previous color.

Even you are expert in Catia VBA programming, but I do believe you are able to help me out on above macro events.

Thank you in advance

Quin
 
 http://files.engineering.com/getfile.aspx?folder=103b181a-d8c8-45d3-b303-365efe657a91&file=PART.JPG
In this catvba macro you need first to select the body and after that run the macro. I believe is written clear in the message.

If you want to let user to pick something after launching the macro, you need something else but once again, if you want to learn, search first a solution thinking before what you want to achieve with the macro, and think to steps of your macro, for example:

1) first preselect the feature/body or let user select after hit run macro ?
2) get the color and store it
3) set new color
4) change the background, zoom the part, iso position, compass off, tree structure off?
4) take the screenshot?
a.s.o. ........

There are several macros on web regarding this, also you can find in CATIA_Portable_Script_Center.

Capture_2_x3cytf.jpg


Regards
Fernando

- Romania
- EU
 
Thank you Ferdo,

I got your VBA code and patiently modified it to obtain the partbody color, display color in array (RGB) numbers and set partbody's color to white color. Now I turn my attention to:

1) How do I store/save color array numbers for later usage or apply them back to the partbody later?
2) How do I switch Annotation Set on and off? I looked at SwitchOn() function in V5Automation.chm file, tried a few ways but not able to switch annotation set on or off yet.
3) How do I correctly zoom the screens to a desired appearance on screen in order to capture the screens legibly? I got a partial code to print a single screen out to JPG but the image is either too small to read or too big out of the paper margin.
4) Where is CATIA_Portable_Script_Center? In the forum of ENG_TIPS.com?

Thank you again

Quin
 

you already have other posts open, please don't mix post topic.



Eric N.
indocti discant et ament meminisse periti
 
Hi Ferdo,

I opened your CATIA_PORTABLE_SCRIPT_CENTER.chm in Catia 2015, clicked a few documents as seen on attached image, but nothing is shown?

Have I missed something or your file needs something else to open those files?

Please kindly advise asap.

Thank you

Quin
 
 http://files.engineering.com/getfile.aspx?folder=02f577f1-200b-4ca0-8d06-c5169fd72aa3&file=Capture.JPG
If you are just doing this for screenshots, an easier approach would be to place the CATPart into the context of a CATProduct. The color can be changed, impacting the appearance of the CATProduct w/o altering the color of the CATPart. To return to the CATPart colors, set the color to automatic for the CATPart within the CATProduct context.

Extending this line of reasoning, if you have a number of CATParts you want to get a screenshot of, replace the CATPart in the CATProduct while leaving the desired screenshot color assigned to the contextual CATPart.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top