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:

Copying entitys at certain depths


webemachining2
 Share

Recommended Posts

Try out this script. It'll prompt you for a Z depth and a level. The script will then go through all of the entites and move all entities at the depth that you entered to the level that you entered:

 

code:

'///////////////////////////////////////////////////////////////////////////////

'//

'// Author: Chris Bellini [email protected]

'// Copyright © 2006 In-House Solutions Inc.

'// Date: 01/26/2006 1:44 PM

'// File Name: webemachining2.vbs

'// Description: Prompts the user to enter Z depth and level values. Then scans

'// the database of the current MC9 for entities at the matching Z

'// depth. Those matching entities are moved to the user-selected

'// Level.

'//

'//

'//

'// Comments:

'// - 01/26/2006 <cvb>: initial version

'//

'//

'// ----------------------------------------------------------------------------

'// This library is free software; you can redistribute it and/or

'// modify it under the terms of the GNU Lesser General Public

'// License as published by the Free Software Foundation; either

'// version 2.1 of the License, or (at your option) any later version.

'//

'// This library is distributed in the hope that it will be useful,

'// but WITHOUT ANY WARRANTY; without even the implied warranty of

'// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

'// Lesser General Public License for more details.

'//

'// You should have received a copy of the GNU Lesser General Public

'// License along with this library; if not, write to the Free Software

'// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,

'// MA 02110-1301, USA

'///////////////////////////////////////////////////////////////////////////////

 

' Kick off the script.

Call Main()

 

' Purpose: The main subroutine

Sub Main()

Dim objArc, objLine, objPoint, objRectangle ' entity objects

Dim dTargetDepth ' depth to look for

Dim iTargetLevel ' level to move entities to

Dim iCurrEnt ' entptr of current entity

Dim bMove ' move to the new level?

Dim iMoveCount : iMoveCount = 0 ' number of entities we moved

Dim bSuccf ' success flag

 

 

' Make sure there is a file open with geometry in it.

If Not (IsDrawing()) Then

ShowString "File is empty. Aborting."

Exit Sub

End If

 

' Promt user for depth to look for.

If Not (askValue("Depth: ", -100.0, 100.0, dTargetDepth)) Then

ShowString ("Script aborted")

Exit Sub

End If

 

' Prompt user for level to move matching entities to.

If Not (askNumber("Level to move to: ", 1, 255, iTargetLevel)) Then

ShowString ("Script aborted")

Exit Sub

End If

 

' Start searching the database

bSuccf = StartDBSearch(mc_alive, mc_arctype Or mc_pointtype Or mc_linetype Or mc_recttype)

 

' Loop through the database of entities and retrieve the depth of each entity. If it's

' the same as the depth value that the user entered, set a flag to move the entity

' to the user-selected level.

Do While bSuccf

' Get the current entity pointer

iCurrEnt = GetEntityEptr()

 

' Initialize the move flag to FALSE

bMove = False

 

' Get the depth of the current entity. If it has the same depth as the one that

' the user entered, set the move flag to TRUE.

Select Case GetEntityType

Case mc_arctype

Set objArc = New McAr

 

If GetArcData(iCurrEnt, objArc) Then

If (objArc.Z = dTargetDepth) Then bMove = True

End If

 

Case mc_linetype

Set objLine = New McLn

 

If GetLineData(iCurrEnt, objLine) Then

' Move lines with endpoints at the same depth.

If (objLine.Z1 = dTargetDepth) And (objLine.Z2 = dTargetDepth) Then bMove = True

End If

 

Case mc_pointtype

Set objPoint = New McPt

 

If GetPointData(iCurrEnt, objPoint) Then

If (objPoint.Z = dTargetDepth) Then bMove = True

End If

 

Case mc_recttype

Set objRectangle = New McRe

 

If GetRectangleData(iCurrEnt, objRectangle) Then

If (objRectangle.Z = dTargetDepth) Then bMove = True

End If

End Select

 

' If the move flag is set, move the entity to the chosen level.

If (bMove) Then

SetEntityLevel(iTargetLevel)

iMoveCount = iMoveCount + 1

End If

 

' Get the next entity

bSuccf = NextDBSearch()

Loop

 

' Cleanup

Set objArc = Nothing

Set objLine = Nothing

Set objPoint = Nothing

Set objRectangle = Nothing

 

' All done!

ShowString iMoveCount & " entites at Z=" & dTargetDepth &_

" have been move to Level " & iTargetLevel & "."

End Sub

 

 

' Purpose: Determine if there is valid geometry on the screen.

' I: (None)

' O: True=valid geo, False=invalid geo

Function IsDrawing()

Dim bRet

 

 

bRet = StartDBSearch(mc_alive, -1)

IsDrawing = bRet

End Function

HTH

Link to comment
Share on other sites

Bullines,

I tried running the script above, but get the following error message:

 

Microsoft VBScript compilation error

Expected end of statement

IActiveScriptSite:;OnScriptError()

Line: Set objLine=Nothing Set objPoint=Nothing

 

What did I do wrong? Did I get something copied wrong? I ran it on a file that had a bunch of entitities that I could separate a chain from the wireframe.

Running X MR1

 

Thanks

lynnz

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...