Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

How to automate Coloring


Terry_1230
 Share

Recommended Posts

Terry,

 

Here is a VB Script that sets the Color of all (visible) Arcs, based on their Radius.

 

'////////////////////////////////////////////////////////////////////////////////
'//
'//        Author:   CNC Software, Inc.
'//          Date:   10-May-2011
'//     File Name:   Set Arc Color by Size.vbs
'//
'//   Description:   Scans the database for all of the visible Arc entities and
'//          changes their color based on a lookup from a pre-loaded Dictionary.
'//
'//           See: 1> "Load the Dictionary with the Arc Size to Color mappings"
'//                   for where you specifiy the arc (radius) sizes to match and 
'//                   and Mastercam Color# to set on arcs that match that size.
'//                2> The "bOnlyCircles" setting under *** User Settings ***
'//                3> The "rTolerance" setting under *** User Settings ***
'//
'//         Notes: 1> It only finds Arcs that are "visible", meaning any Arcs on levels
'//                   that are turned off with not be processed.
'//                2> You can restrict the processing to only "full" circles
'//                   by setting: bOnlyCircles = True ' Set this to True or False !
'//                3> You set the matching "tolerance" by setting the rTolerance variable.
'//                   This specifies the # of digits to round the arc radius 
'//                   of each arc that is "looked at". This would usually be: 3, 4 or 5 
'//
'////////////////////////////////////////////////////////////////////////////////

' -- Start Script
Call Main()


' ////////////////////
' Sub Declaration
' ////////////////////
Sub Main()

Dim bRet             ' Success/Failure flag
Dim CArc             ' The Arc Class data
Dim rArcSize         ' The Radius of the current Arc
Dim iColor           ' The "value" (Color#) from a Dictionary entry
Dim iTotalProcessed  ' The number of arcs that were modified
Dim iTotalCount      ' The total number of arcs that were "found" 
Dim iTotalChecked    ' The total number of arcs that were "checked" against the Dictionary
Dim bOnlyCircles     ' Only process full circles?
Dim rTolerance       ' How "close" does the arc size need to be to match?

Dim ColorDictionary  ' The dictionary that will hold the ArcSize->Color# mappings.
Set ColorDictionary = CreateObject("Scripting.Dictionary")

' *** User Settings ***
bOnlyCircles = False  ' Set this to True or False !
rTolerance = 4        ' "Rounding" tolerance for matching on the Arc Radius

' Load the Dictionary with the Arc Size to Color mappings.
With ColorDictionary
 ' Add items to the dictionary.
 ' The Arc Radius is the "key" and the Color# is the "value"
  .Add 0.266  , 11
  .Add 0.375  , 12
  .Add 0.398  , 13  
End With

iTotalCount  = 0    ' Initialize the counter
iTotalChecked = 0   ' Initialize the counter
iTotalProcessed = 0 ' Initialize the counter

' -- Start our search: Get all Arcs that are "Alive" (and Visible)
bRet = StartDBSearch(mc_alive, mc_arctype) 

' -- Loop while we have something
Do While bRet
 Set CArc = New McAr
 If GetArcData(GetEntityEptr, CArc) Then 
   iTotalCount = iTotalCount + 1 ' Total # of arcs that were "found"
   If Not bOnlyCircles Or (bOnlyCircles And CArc.SW = 360.0) Then
     rArcSize = Round(CArc.R, rTolerance)
     'ShowString "rArcSize = " & rArcSize  ' *DEBUG* - What is the "Rounded" value?
     iTotalChecked = iTotalChecked + 1 ' The total number of arcs that were "checked" against the Dictionary
     ' Do we have this Arc size in the Dictionary?     
     If ColorDictionary.Exists(rArcSize) Then 
       ' Retrieve the Color for this Arc size from the Dictionary
   iColor = ColorDictionary.Item(rArcSize)         
   SetEntityColor iColor
   iTotalProcessed = iTotalProcessed + 1 ' The # of Arcs and/or Circles that were "processed"
     End If
   End If
 End If    

 Set CArc = Nothing

 ' -- Get another entity
 bRet = NextDBSearch     

Loop 

' -- Done
Call RepaintScreen(True) 

Dim msg
msg = iTotalCount & " arcs were found." & vbCrLf _
     & iTotalChecked  & " arcs were checked." & vbCrLf _
     & iTotalProcessed & " arcs were processed." 
ShowString msg

End Sub                           

  • Like 1
Link to comment
Share on other sites

Roger I have been wondering the same thing and used your vb script, added hole sizes with differnt colors. I then drew all the sizes I added,ran the vbscript and only three sizes changed colors. The color library is the same as the color pallette # aren't they?

Link to comment
Share on other sites

Wow that worked great. It would be nice if there was a website that had a bunch of these

scripts to use as templates....

Probably could save allot of people time.

Thank you very much.

 

Out of curiosity do you know of any similar way to change the colour of different size cylinders?

(for example different size holes through a 3d surfaced block)

Link to comment
Share on other sites

The sample VB Scripts are in the VB folder of your Mastercam install.

I did not have this Color my Circles script lying around, I whipped it up when I noticed your initial posting. ;)

 

Out of curiosity do you know of any similar way to change the colour of different size cylinders?

(for example different size holes through a 3d surfaced block)

This is a completely different animal.

We don't have Arcs/Circles to work with and you'd need someway (which your not going to do with a Script) to identify;

1> What is a circular hole?

2> If so, what is it's size?

Link to comment
Share on other sites

It is working but it doesn't seem to be picking all the visible arcs.

I have tried deleting duplicates, combining views, turning on one level at a time, and bOnlyCircles to = true and false

(false comes up with more but not all visible ones). If i put, .Add 0.398 , 55 it only picks up 60 of the 115 arcs.

Any ideas would be great.

Link to comment
Share on other sites

It is working but it doesn't seem to be picking all the visible arcs.

I have tried deleting duplicates, combining views, turning on one level at a time, and bOnlyCircles to = true and false

(false comes up with more but not all visible ones). If i put, .Add 0.398 , 55 it only picks up 60 of the 115 arcs.

Any ideas would be great.

 

 

That was the problem I was having also. I thought it was a color thing. I found after soom experimentationthat itt actually only recognizes sizes that are in the 1/32 incremaent ranges (Radius) in the smaller #'s then it goes by 1/16th increment on the larger #'s starting around .25r. It may have to do with the way it filters to the next size. Just a guess.

Link to comment
Share on other sites

There is tons of stuff on VB Script out there "on the 'Net".

If you get those basics down, then you have a better chance of understanding and using the Mastercam specific stuff.

 

I am definitely not a VB Script expert - not even close.

I've done some here and there so everytime I do use it, I end up looking up lots of "how do I do that again?" on the 'NET.

It's .NET -> C# and C++/CLI for me. B)

and C++/MFC 'cause that helps pay the bills. :D

Even VB.NET makes my eyes hurt reading it. - Which is exactly what I've been doing for the last 4 hours! :blink:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...