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:

vbscript object library?


wtsylvester
 Share

Recommended Posts

I regsvr32'ed the dll example got that to worked played around with the code in VB6 , changed it around to do more or less the same thing in acad2000 .

I was wondering if there is a way to reference the mcam commands in vb ,like i can with the acad stuff..or is it like apples and oranges, vba vs vbscript

Also in the entity commands of mcam , is there a method I can loop thru all the entites and do thing based on entity ...name..type?

 

for each ent in mcamdatabase

case select or if statements here

next ent

 

and while we are at it smile.gif fso... FileSystemObject

 

something like

dowhile not eof(1) to read in data

 

may not make much sense , I don't have my examples here with me

granted all this with proper dim statements etc

 

tia ..Bill

Link to comment
Share on other sites

wtsylvester,

 

You can't reference Mastercam from VB, you have to write VBS scripts that Mastercam will execute.

 

To iterate over entities look at the StartDBSearch and NextDBSearch functions, you can use a looping structure and a select case combination to get what you need.

 

Tip:When in the editor, use the right click popup menu to access the Quick Code menu's one of the declarations is the file system object.

 

code:

Dim FSO

 

Set FSO = CreateObject("Scripting.FileSystemObject")

Check the new updated VBS chook as there are additional quick code additions.

Link to comment
Share on other sites

Mick,

Right got what you are saying. So I will have to vbscript any info I want to pump out of vb6 with a FileScriptObject..so I put in some eof marker in that file with vb, read with the fso in the vbs until I hit marker....to grab any undetermined size file .. case select in the vbscript to base actions or fill in the blanks

of what I want do to.

It's all pretty cool. I try and work in some of this during runtime. Mastercam makes things so easy to begin with I don't know why I bother smile.gif

 

Back to subject, I sort of don't see why the dll

Seems like I can just write to a file with a VB6.exe, maybe have a shell to that , then use vbs to read it in and do it's thing.Don't really know enough about that end of things.

 

So, I can see input, I really don't quite know where to go on output, I see the writing of the

fso. I don't understand looping thru mcam

 

//// Database Search functions

 

// initialize for database searching

 

Bool StartDBSearch(

 

Integer, (Input: entity bits “or”ed together)

 

Integer (Input: entity Ids “or”ed together)

 

)

 

 

 

// get the first or next entity in the database and make it the current active entity

 

Bool NextDBSearch()

 

I mean who's ed smile.gif wouldn't that be mc_ed < sorry couldn't help myself smile.gif > mc_selected ??

How do I go between the upper and lower number of entitys in the database. I guess I really need an example

 

tia sylvester

Link to comment
Share on other sites

wtsylvester

 

Have a play with this script.

 

code:

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

'//

'// Author: Mick George [email protected]

'// Date: 30/12/2003 02:34 PM

'// File Name: Search DB Demo.vbs

'//

'// Description: Example of looping through database for entities

'//

'// Comments:

'//

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

 

 

'///////////////// My Constants /////////////////

Const DEF_ALL_ENTITIES = -1

 

 

'///////////////// My Global Variables //////////

 

 

 

' -- Start Script

Call Main()

 

 

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

' Sub Declaration

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

Sub Main()

 

Dim bRet

Dim CArc

Dim CPoint

Dim CLine

 

' -- Initiate a search through our database

bRet = StartDBSearch(mc_alive, DEF_ALL_ENTITIES)

 

' -- Ok?

If bRet Then

 

Do

Select Case GetEntityType

 

Case mc_arctype

 

Set CArc = New McAr

 

If GetArcData(GetEntityEptr, CArc) Then

ShowString "Arc radius = " & CArc.R & " on level " & GetEntityLevel

SetEntityColor mcCOLOR_LIGHTGREEN

End If

 

Case mc_linetype

 

Set CLine = New McLn

 

If GetLineData(GetEntityEptr, CLine) Then

ShowString "Line Z1 = " & CLine.Z1 & " On level " & GetEntityLevel

SetEntityColor mcCOLOR_PURPLE

End If

 

Case mc_pointtype

 

Set CPoint = New McPt

 

If GetPointData(GetEntityEptr, CPoint) Then

ShowString "Point X = " & CPoint.X & " on level " & GetEntityLevel

SetEntityColor mcCOLOR_LIGHTBLUE

End If

 

Case mc_recttype

 

Case Else

'

ShowString "?"

'

End Select

 

' -- Move forward in DB

Loop While NextDBSearch

 

 

Else

 

ShowString "No entities found in current drawing"

 

End If

 

 

 

End Sub

Link to comment
Share on other sites

thanks for the code.

I am a bit curious in the vbscript help file it says

// get the eptr of the current active entity (see colors above)

 

Integer GetEntityEptr()

 

where it says "colors" should that be refering to the part about classes instead of "colors"

It seems to me that this is the entity info that brings out the variant info about point locations, radius etc. of that entity

make sense??? smile.gif

Bill

Link to comment
Share on other sites

Ok Mick could you then expand this Script to ask you for the colors you want to assign on each of the entites that you have there. I am also wondering if you could do an assiging of the levels you want for each one of them also. I may use 40 different colors as wells as levels so be cool if I could put them out there in the 100 levels with colors I might like.

 

Maybe I am off here but the code is making more and more sense everyday. I am playing with 3 of your scripts right now and think I might have something that is going to come out very cool. I will put it up when I get it all the way I like it and working which I know will be the hardest part. I know will have 5 different posts in which we will be using and that does not include the one post I need to be able to run bigger than 20 mb files over the ethernet for the new HAAS machines. I looked at your stripping script and thinking about adding into the 3 scripts as a run time option for that machine when using one of the posts I run now. I couldn't play with it while off didn't bring the dongle home for the last 6 days that I have been off. I have got to page 300 in that book I got and I am know in the process of defining all the variablies in scripts I have got here and off the web. Maybe not the most effective way but it works for me.

 

Crazy Millman

Link to comment
Share on other sites

Ok so that went the way I thought it would.

 

The only thing that keeps getting going around and around about the VB is I see things that keep refering back to the IDE. I am thinking that all that is usuable through a object based contruction is also usuable through a script based application as long as you have all the scripts written in such ways as to be usable with Mastercam. The exaples my book keep using always refer back to the meaning of what Vb is Visual where as in Mastercam it tends to lend itself to non visual uses or am I off track in that aspect of using VB in Mastercam

 

Crazy Millman

Link to comment
Share on other sites

VB allows you to create, among other things, a compiled executable program that can, essentially, run on its own; you also have the ability to create user interfaces (forms).

 

VBS does not allow you to create stand alone programs but rather text files that are executed (interpreted) by Windows or a host application in our case Mastercam. There are a number of limitations with VBS namely no provision to create user interfaces, however, you can with a little extra work create user interfaces with VB and use those with a VBS script to give you your UI elements.

 

I would recommend you having a look at the Microsoft VBS help file that can be accessed from Mastercam’s VBScript Editors help menu, as there is a list of differences between VB, VBA and VBS.

 

One example of using VB with VBS is our new Automatic Toolpathing script, all the UI elements you see are contained in a VB6 ActiveX DLL, a MS Access Database is used as the ‘middleware’ component to hold all the information collected from the UI’s and the VBS scripts do all the Mastercam grunt work.

 

You’ll be pleasantly surprised how much you can do with a little extra work in making VB and VBS work together.

Link to comment
Share on other sites

Ok s othe reference there should fill in soem blanks with the commands and suc hthat is used there. I also know some things about Access so that will come in handy there just have to dig that information out and then go at it with that apporach. Mick I will keep playing but a good month off before I think got anything clsoe to a workable things that has not been covered by you guys.

 

Crazy Millman

Link to comment
Share on other sites

So I am seeing how this fits together, with vbs,vb,and vba. Dll', vs a .exe

 

So lets say I want to process some info from Mcam , I use script to get the info then write in script with the fso object.... launch my dll to read that info.. change whatever and write to another file with vb end of things.

Script resumes after dll unloads and then can read info in off the vb written file and use script again to change whatever values based on the orginal mcam file.

I put an word object on a form and did all the

compile, regsvr etc .. so I have a spell checker I can use .. paste into any note etc..

I also put routine on the form load of the dll, with a unload at the end and have a transparent process, back to mcam.

 

So I can see the advantage of the dll because you can script the load/unload, where as the exe would be waiting for user action.

 

Got to looking at the get ops script and can see writing up some secondary ops manager to keep track where certain ops are in op9 files

 

I am curious if there are some open variables, that I can write to. I am taking it for granted that the variable declared in a script are only in effect during the script. Or can the be passed to the next script that runs.

 

I think I may already know the answer to the next question, and that is .. Isthere a way to run the mcam script editor outside of macm, I see that it is a dll also. I wouldn't mind writing some scripts at home , and have the advantage of the inteli-sense. Just not wanting to be taking the hasp home.

 

guess that's it ... like the forum smile.gif

Bill

Link to comment
Share on other sites

Well I think I can answer the last and without buying VD developers kit not really. I know Word Access and soem toehr programs have a Vb editor but not the same as Mastercam so not sure how well they will play together. I would also think you could swap dat between scripts but would have to write a send recieve type script to do so. I say this cuase we send data from a post into a Vb script and vice versa right now with a Multi post and soem others I can think of.

 

Keep on Playing and keep on trying is what I say.

 

Crazy Millman

Link to comment
Share on other sites

Millman

I see you are in Carlsbad, I used to work over on Loker.Made vacuum forming molds for some real nice folks there about 10 years ago.- small world

 

Anywho, I see the dll as a real nice hook, grant Mick can chime here and let me know about restrictions on objects I can have with VB , I added some of the common crotrols, not sure about adding a toolbar etc. I guess there is some packaging tools for sharing dll.s

I have been fooling around mostly inside of autocad, but loading the script reference and trying to stay close to the mcam sytanx as far as writing to files , stuff like that .

Seems I can work some of the code out that way , leaving the mcam at work, had to cut parts and code at the same time .. least for me smile.gif

I pretty much wing it with mcam , but have been into vb for awhile. Script looks alot alike. I can see a number of ways to try it together. You can load the object librarys of acad and solidworks and certainly the mcam people should be enjoying that we are digging the interface.

Didn't mean to get so long winded, Football to watch smile.gif

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