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:

John T.

Verified Members
  • Posts

    189
  • Joined

  • Last visited

Everything posted by John T.

  1. One of the programmers here at work asked me to look into if VBS can do this with mastercam... What he would like to do is convert types of fonts to have a single line inside the font that an engraving tool can follow for a toolpath. Put another way, instead of pocketing out a font, we want to follow a single line for engraving, but follow that fonts style, such as cursive, etc. The font might be "hollow", which would normally mean pocketing, but that is time consuming and uneccessary, so putting a single line inside the font to use as a toolpath is what we're looking for (I'm repeating myself here, but wanna make sure you understand what I'm writing about). We used to have a VB program that could do this, but I haven't talked to the guy who wrote it to see if he still has the source code. Since this can't be done in MC itself,at least not automatically, can this be done?? John
  2. I was playing with this: graphic="J:datatetest.emf" DoMetafile graphic .Selection.ShapeRange.Select .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 16.05, _ 522, 572.85, 243).Select .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ShapeRange.Line.Visible = msoFalse .Selection.InlineShapes.AddPicture FileName=graphic,False,True For some reason, no matter how I change that last line, I can't get it to work. Word gives me an error message saying that its not a valid file name. I know its saving the file, cause I've been able to manually load it into Word. John
  3. CAM Disciple, what do you mean by two groups of tool paths? Do you mean like cutting the same part several times in one set up? Something similar, if we have to cut a feature several times on one part, we use transform. You can also transform the transform for multiple parts. MillMan, Much of the thanks goes to Mick and Bullines. I could not have figured out a lot of it without them, and its still not finished! John
  4. Here's my latest, it does almost everything I need it to do. code: '//////////////////////////////////////////////////////////////////////////////// '// '// Author: John Thompson, with MUCH help from Mick George and Bullines! '// Date: 15/03/2004 04:01 PM '// File Name: New Mastercam Script '// '// Description: Headertest2.vbs '// '// Comments: Makes a job setup sheet. Work in progress! '// '//////////////////////////////////////////////////////////////////////////////// '///////////////// My Constants ///////////////// '///////////////// My Global Variables ////////// ' -- Start Script ' //////////////////// ' Sub Declaration ' //////////////////// Dim wordDoc '///////////////// My Constants ///////////////// Dim companyname Dim Program Dim Description Dim Post Dim programmer Dim notes Dim tlo Dim nCount ' number of operations Dim nToolNum ' tool number Dim arrToolNumber() ' array of tool numbers Dim arrToolComment() ' array of tool comments Dim arrToolDiameter() ' array of tool diameters Dim arrToolFluteLength() ' array of tool flute lengths Dim arrToolLength() ' array of tool lengths Dim idx Dim toolcount Dim strText Dim Position Const wdTabLeaderSpaces = 0 Dim DateTimeFormat() Const wdAlertsNone=0 Const wdWindowStateMaximize=1 Const wdLine=5 Const wdEnglishUS = 1033 Const wdCalendarWestern = 0 Const wdColorDarkRed=128 Const wdAlignParagraphCenter=1 Const msoTextOrientationHorizontal = 1 Const wdTextOrientationDownward = 3 Const msoFalse=0 Const DEF_SPACING_ONEANDAHALF=1 Const wdAlignTabLeft = 2 '///////////////// My Global Variables ////////// ' -- Start Script Call Main() ' //////////////////// ' Sub Declaration ' //////////////////// Sub Main() 'WriteString("Company Name?") companyname=AskString("company Name?") Program=AskString("program number?") Description=AskString("description") Post=AskString("fadal") ' -- You can call GetPostName() mag programmer=AskString("programmer?") notes=AskString("Notes") tlo=AskString("TL0") 'Load tool information ' get the number of operations nCount = GetOperationCount("") If nCount = 0 Then ShowString "No operations found in current drawing": Exit Sub For idx = 1 To nCount ' get the tool number using the current operation nToolNum = GetToolNumberFromOperationID("", idx) ReDim Preserve arrToolNumber(idx) ReDim Preserve arrToolComment(idx) ReDim Preserve arrToolDiameter(idx) ReDim Preserve arrToolFluteLength(idx) ReDim Preserve arrToolLength(idx) ' copy tool data into our individual arrays arrToolNumber(idx) = nToolNum arrToolComment(idx) = GetToolComment(nToolNum) arrToolDiameter(idx) = GetToolDiameter(nToolNum) arrToolFluteLength(idx) = GetToolFluteLength(nToolNum) arrToolLength(idx) = GetToolLength(nToolNum) Next Set wordDoc=CreateObject("Word.Application") wordDoc.Documents.Add With wordDoc .Visible=True .WindowState=wdWindowStateMaximize .DisplayAlerts=wdAlertsNone 'Sets Margins .Selection.PageSetup.LeftMargin = .InchesToPoints(0.5) 'start of margin setting macro .Selection.PageSetup.RightMargin = .InchesToPoints(0.5) .Selection.PageSetup.TopMargin = .InchesToPoints(0.5) .ActiveWindow.ActivePane.VerticalPercentScrolled = 20 .Selection.PageSetup.BottomMargin = .InchesToPoints(0.5) 'end of margin setting macro 'Puts "Program Info" top center .Selection.Font.Bold=True .Selection.Font.Size=20 .Selection.ParagraphFormat.Alignment=wdAlignParagraphCenter .Selection.Font.Name="staccato222 BT" '.Selection.Font.Color =wdColorDarkRed 'Running low on red ink! .Selection.TypeText "PROGRAM INFO" .Selection.TypeText vbNewLine 'Puts program number in sideways box, right side .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 525, 75, 45, 117).Select 'start of macro code .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ShapeRange.Line.Visible = msoFalse .Selection.ShapeRange.Select .Selection.ShapeRange.IncrementLeft 36 ' -- Removed # not valid in VBS mag .Selection.ShapeRange.IncrementTop -18 .Selection.Orientation = wdTextOrientationDownward .Selection.Font.Size = 24 .Selection.TypeText Program 'double text boxes for header info .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 20,80, 222.3, 80).Select 'first box left side .Selection.ShapeRange.TextFrame.TextRange.Select 'First box header info goes this section .Selection.Collapse .Selection.ShapeRange.Line.Visible = msoFalse .Selection.Font.Bold=True .Selection.TypeText "Company: "&vbTab 'Company Name .Selection.Font.Bold=False .Selection.TypeText companyname&vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Description: "&vbTab 'Description .Selection.Font.Bold=False .Selection.TypeText Description &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "PI Num: "&vbTab 'PI number .Selection.Font.Bold=False .Selection.TypeText Program &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Name: "&vbTab 'Programmer Name .Selection.Font.Bold=False .Selection.TypeText programmer&vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Date "&vbTab&vbTab 'Date .Selection.Font.Bold=False .Selection.InsertDateTime "M/D/YY", False, False, wdEnglishUS, wdCalendarWestern 'get the date 'Second Header box .Selection.ShapeRange.Select .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 259,80, 300, 80).Select 'second box right side .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ShapeRange.Line.Visible = msoFalse .Selection.Font.Bold=True .Selection.TypeText "Filename: "&vbTab&vbTab 'File Name .Selection.Font.Bold=False .Selection.TypeText GetCurrentFileName()&vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Post: "&vbTab&vbTab&vbTab 'Post .Selection.Font.Bold=False .Selection.TypeText Post &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Material Type "&vbTab 'Material type IF in Job setup .Selection.Font.Bold=False .Selection.TypeText GetJobSetupMaterial() &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Stock Size: "&vbTab&vbTab 'Stock size IF in job setup .Selection.Font.Bold=False .Selection.TypeText "X"&GetJobSetupStockSizeX&" Y"&GetJobSetupStockSizeY&" Z"&GetJobSetupStockSizeZ &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Stock Origin: "&vbTab 'Stock origin from job setup. Almost always 0,0 .Selection.Font.Bold=False .Selection.TypeText "X"&GetJobSetupStockOriginX&" Y"&GetJobSetupStockOriginY&vbNewLine 'Print out notes .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 20, _ 153, 567.15, 30).Select .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ShapeRange.Line.Visible = msoFalse .Selection.Font.Bold=True .Selection.TypeText "NOTES: " .Selection.Font.Bold=False .Selection.TypeText notes 'Revisions listing .Selection.ShapeRange.Select .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 20, _ 198, 575.7, 50).Select .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ShapeRange.Line.Visible=msoFalse .Selection.Font.Bold=True .Selection.TypeText "Revisions:"&vbNewLine .Selection.TypeText "Name:________"&vbTab&"Name:________"&vbTab&"Name:________"&vbTab&"Name:_______"&vbTab&"Name:________"&vbNewLine .Selection.TypeText "Date:________"&vbTab&"Date:________"&vbTab&"Date:________"&vbTab&"Date:_______"&vbTab&vbTab&"Date:________" 'puts out tool list 'creat 2 text boxes 'left side box .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 20, _ 250, 270, 225).Select '.ActiveDocument.Paragraphs.TabStops.ClearAll '.Selection.ParagraphFormat.TabStops.Add Position=.InchesToPoints(0.51),.Alignment=wdAlignTabLeft, .Leader=wdTabLeaderSpaces '.Selection.ParagraphFormat.TabStops.Add Position=.InchesToPoints(1.58),.Alignment=wdAlignTabLeft, .Leader=wdTabLeaderSpaces '.Selection.ParagraphFormat.TabStops.Add Position=.InchesToPoints(2.14),.Alignment=wdAlignTabLeft, .Leader=wdTabLeaderSpaces '.Selection.ParagraphFormat.TabStops(InchesToPoints(2.61)).Position =.InchesToPoints(2.69) .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ParagraphFormat.LineSpacingRule=DEF_SPACING_ONEANDAHALF 'Change line spacing to 1 and a half .Selection.ShapeRange.Line.Visible = msoFalse .Selection.Font.Bold=True .Selection.TypeText "Tool"&vbTab&"Description"&vbTab&" "&"Dia "&vbTab&"Flute"&vbTab&"Overall" .Selection.Font.Bold=False toolcount=1 'prints first tool strText="T"&arrToolNumber(1)& vbTab & _ arrToolComment(1) & vbTab &" "& _ arrToolDiameter(1) & vbTab&" " & _ arrToolFluteLength(1) & vbTab & _ arrToolLength(1) Call WriteToWord(strText)'sends first tool to word For idx=1 To nCount If toolcount<=9 Then If toolcount<>GetToolNumberFromOperationID("",(idx)) Then strText = "T"&arrToolNumber(idx)& vbTab & _ arrToolComment(idx) & vbTab &" " & _ arrToolDiameter(idx) & vbTab&" "& _ arrToolFluteLength(idx) &vbTab& _ arrToolLength(idx) Call WriteToWord(strText) toolcount=toolcount+1 End If End If Next 'Right side box .Selection.ShapeRange.Select .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 310, _ 250, 270, 225).Select .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ParagraphFormat.LineSpacingRule=DEF_SPACING_ONEANDAHALF .Selection.ShapeRange.Line.Visible = msoFalse .Selection.Font.Bold=True .Selection.TypeText "Tool"&vbTab&"Description"&vbTab&" "&"Dia"&vbTab&"Flute"&vbTab&"Overall" .Selection.Font.Bold=False 'Second column of tools toolcount=11 'toolcount=1 For idx=1 To nCount If toolcount >= 10 Then If toolcount=GetToolNumberFromOperationID("",(idx)) Then strText = "T"&arrToolNumber(idx)& vbTab & _ arrToolComment(idx) & vbTab &" " & _ arrToolDiameter(idx) & vbTab&" "& _ arrToolFluteLength(idx) &vbTab& _ arrToolLength(idx) Call WriteToWord(strText) toolcount=toolcount+1 End If End If Next 'Put TL0 information in .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 20, _ 485, 564.3, 35).Select .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ShapeRange.Select .Selection.ShapeRange.Line.Visible = msoFalse .Selection.Font.Bold=True .Selection.TypeText "T.L.0. Location: " .Selection.Font.Bold=False .Selection.TypeText tlo&vbNewLine .Selection.TypeText "_________________________________________________________________________________________" End With If Not wordDoc Is Nothing Then Set wordDoc = Nothing ShowString "Script has ended" End Sub ' Writes tool list to word Public Sub WriteToWord(strOutText) Dim wordCounts With wordDoc .Selection.MoveDown wdLine, .ActiveDocument.Words.Count .Selection.TypeParagraph .Selection.TypeText strOutText End With End Sub You'll noticed I tried to work with tabbing. If the tool diameter was more than 3 decimal places, it bumped the flute and overall columns over for that tool. I didn't get that to work, but it wasn't a priority (yet). I now need to get the EMF file to go on the remainder of the page. I started a new topic for that. The logic to split the tool list into 2 columns turned out to be devilishly simple. Future stuff includes getting the prompt to work when asking for the information at the top (company, number, etc), check stock sizes and asking if want to change if they are 0, use the default tool dimensions or input your own, and so on. I also need to test this program on files that are missing a tool, or reuse a tool later on in the program, or tools out of sequence. John
  5. How does it work? In the HTML setup sheet, the EMF file is generated by taking a snapshot of the (skeletonized) part view thats currently in MC, then puts it on the setup sheet. How do I make it work in MC/VBscript. I need to have it output to the VBS setup sheet I'm working on. John
  6. Is there a way to put a space and a half between lines instead of one space? John
  7. Gee, I think I have a NEW! UNOPENED! STILL IN SHRINK WRAP! version 7 MC demo from a school trip to a tool show. Hey yeah, I can also list it as a "collectible"! Whoo! I'm gonna be rich! John
  8. Here's what I've done so far tonight. code: Dim wordDoc '///////////////// My Constants ///////////////// Dim companyname Dim Program Dim Description Dim Post Dim programmer Dim notes 'Dim whatdate() Dim DateTimeFormat() Const wdAlertsNone=0 Const wdWindowStateMaximize=1 Const wdLine=5 Const wdEnglishUS = 1033 Const wdCalendarWestern = 0 Const wdColorDarkRed=128 Const wdAlignParagraphCenter=1 Const msoTextOrientationHorizontal = 1 Const wdTextOrientationDownward = 3 Const msoFalse=0 '///////////////// My Global Variables ////////// ' -- Start Script Call Main() ' //////////////////// ' Sub Declaration ' //////////////////// Sub Main() 'WriteString("Company Name?") companyname=AskString("company Name?") Program=AskString("program number?") Description=AskString("description") Post=AskString("fadal") ' -- You can call GetPostName() mag programmer=AskString("programmer?") notes=AskString("Notes") Set wordDoc=CreateObject("Word.Application") wordDoc.Documents.Add With wordDoc .Visible=True .WindowState=wdWindowStateMaximize .DisplayAlerts=wdAlertsNone ' -- InchesToPoints is an App method mag .Selection.PageSetup.LeftMargin = .InchesToPoints(0.5) 'start of margin setting macro .Selection.PageSetup.RightMargin = .InchesToPoints(0.5) .Selection.PageSetup.TopMargin = .InchesToPoints(0.5) .ActiveWindow.ActivePane.VerticalPercentScrolled = 20 .Selection.PageSetup.BottomMargin = .InchesToPoints(0.5) 'end of margin setting macro 'Puts "Program Info" top center .Selection.Font.Bold=True .Selection.ParagraphFormat.Alignment=wdAlignParagraphCenter .Selection.Font.Name="staccato222 BT" '.Selection.Font.Color =wdColorDarkRed 'Running low on red ink! .Selection.TypeText "PROGRAM INFO" .Selection.TypeText vbNewLine 'Puts program number in sideways box, right side .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 525, 75, 45, 117).Select 'start of macro code .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ShapeRange.Line.Visible = msoFalse .Selection.ShapeRange.Select .Selection.ShapeRange.IncrementLeft 36 ' -- Removed # not valid in VBS mag .Selection.ShapeRange.IncrementTop -18 .Selection.Orientation = wdTextOrientationDownward .Selection.Font.Size = 24 .Selection.TypeText Program 'double text boxes for header info .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 20.3,72, 222.3, 80).Select 'first box left side .Selection.ShapeRange.TextFrame.TextRange.Select 'First box header info goes this section .Selection.Collapse .Selection.ShapeRange.Line.Visible = msoFalse .Selection.Font.Bold=True .Selection.TypeText "Company: "&vbTab 'Company Name .Selection.Font.Bold=False .Selection.TypeText companyname&vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Description: "&vbTab 'Description .Selection.Font.Bold=False .Selection.TypeText Description &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "PI Num: "&vbTab 'PI number .Selection.Font.Bold=False .Selection.TypeText Program &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Name: "&vbTab 'Programmer Name .Selection.Font.Bold=False .Selection.TypeText programmer&vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Date "&vbTab 'Date .Selection.Font.Bold=False '.Selection.InsertDateTime (DateTimeFormat= "M/d/yy", InsertAsField =False,DateLanguage =wdEnglishUS, CalendarType= wdCalendarWestern,InsertAsFullWidth= False) 'Earlier attempt at getting the date ' Call getthedate() '.Selection.TypeText Time 'Second Header box .Selection.ShapeRange.Select .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 259,72, 280.35, 80).Select 'second box right side .Selection.ShapeRange.TextFrame.TextRange.Select .Selection.Collapse .Selection.ShapeRange.Line.Visible = msoFalse .Selection.Font.Bold=True .Selection.TypeText "Filename: "&vbTab&vbTab 'File Name .Selection.Font.Bold=False .Selection.TypeText GetCurrentFileName()&vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Post: "&vbTab&vbTab&vbTab 'Post .Selection.Font.Bold=False .Selection.TypeText Post &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Material Type "&vbTab 'Material type IF in Job setup .Selection.Font.Bold=False .Selection.TypeText GetJobSetupMaterial() &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Stock Size: "&vbTab&vbTab 'Stock size IF in job setup .Selection.Font.Bold=False .Selection.TypeText "X"&GetJobSetupStockSizeX&" Y"&GetJobSetupStockSizeY&" Z"&GetJobSetupStockSizeZ &vbNewLine .Selection.Font.Bold=True .Selection.TypeText "Stock Origin: "&vbTab 'Stock origin from job setup. Almost always 0,0 .Selection.Font.Bold=False .Selection.TypeText "X"&GetJobSetupStockOriginX&" Y"&GetJobSetupStockOriginY&vbNewLine 'Print out notes End With If Not wordDoc Is Nothing Then Set wordDoc = Nothing ShowString "Script has ended" End Sub 'Sub getthedate() ' whatdate=InsertDateTime (DateTimeFormat= "M/d/yy", InsertAsField =False,DateLanguage =wdEnglishUS, CalendarType= wdCalendarWestern,InsertAsFullWidth= False) 'End Sub You'll notice I have the askstring and date stuff commented out. I don't know how to have the prompt string show above the input line at the bottom of mastercam like it does on the .SET sheets. Second, I couldn't get the datetime thing to work. If I understand it right, its supposed to be a subroutine, but I can't get it to work right. The one in the above code is pretty hacked up from the Word macro, but as it is right now, I get a "mismatch" error message. You'll notice I use textboxes for the information. I think I'll have to use these through the whole document? I next need to make a text box for the notes two lines long across the whole page, then 2 longer side by side boxes for the tool list, then a one line text box below then for the TL0 location, then finally one more text box filling the remainder of the page for the graphic of the part. John
  9. well smack me upside the head. I didn't realize tht the clickable "WdTextOriention" at the bottom of the object browser was clickable until after I left the last message. NOW I see! That should be a giant leap forward now! John
  10. Mick, Browsing through Word's object browser screen, with the "Word" selected in the upper left dropdown. Using the example you wrote, I looked up "selection (classes column on left)-oriention (members of "selection" on right), and on the bottom, it tells me "Property Oriention as WdTextOriention". Now, I can get the "wdTextOrientionDownward" from the recorded macro, but how do you know to define the constant wdTextOriention as 3 in the constant definitions? This is what puzzles me in this code. how do I find out what these number mean, or which numbers are required in defining these constants? In playing around with centering a pargraph, I discovered that the constant for orienting a paragraph (forgot what it was right now, have it noted) to =1 seems to "turn it on". Obviously, not all definitions are 0/1 or on/off. John
  11. Mick, How can I find information as to what those Const wdXxxxxx = X values should be? That seems to be a stumbling block for me. I'm at home now (4 day workweek!), so will give your code a try Monday. A bit eerie how Bullines and Mick came up with the same program It really seems to be the little things like the # sign and text:= that aren't allowed in VBS that are tripping me up because I don't know that. You guys have been a lot of help!
  12. Mick, Heres the code in question. I've noted the 2 macros I've been trying, and are causing problems. The first one is supposed to set margins, the second one a vertical, rotated text box on the upper right. The margin code seems to be asking to have the InchesToPoints defined first, and the text box code keeps insisting there needs to be a right parentheses ")" John code: Dim wordDoc '///////////////// My Constants ///////////////// Dim companyname Dim Program Dim Description Dim Post Dim programmer Const wdAlertsNone=0 Const wdWindowStateMaximize=1 Const wdLine=5 '///////////////// My Global Variables ////////// ' -- Start Script Call Main() ' //////////////////// ' Sub Declaration ' //////////////////// Sub Main() WriteString("Company Name?") companyname=AskString("company Name?") Program=AskString("program number?") Description=AskString("description") Post=AskString("fadal") programmer=AskString("programmer?") Set wordDoc=CreateObject("Word.Application") wordDoc.Documents.Add With wordDoc .Visible=True .WindowState=wdWindowStateMaximize .DisplayAlerts=wdAlertsNone .Selection.PageSetup.LeftMargin = InchesToPoints(0.5) 'start of margin setting macro .Selection.PageSetup.RightMargin = InchesToPoints(0.5) .Selection.PageSetup.TopMargin = InchesToPoints(0.5) .ActiveWindow.ActivePane.VerticalPercentScrolled = 20 .Selection.PageSetup.BottomMargin = InchesToPoints(0.5) 'end of margin setting macro .ActiveDocument.Words(1).Text="Company "&companyname&vbTab&"Program "&Program&vbTab&"Dir "&GetCurrentFileName()&vbNewLine & _ "Description "&Description&"Post "&post&" Stock Size "&GetJobSetupStockSizeX&" X "&GetJobSetupStockSizeY&" X "&GetJobSetupStockSizeZ .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 513#, _ 108#, 45#, 117#).Select 'start of macro code .Selection.ShapeRange.TextFrame.TextRange.Select ' should put the "Program" string in a vertical box .Selection.Collapse .Selection.ShapeRange.Select .Selection.ShapeRange.IncrementLeft 36# .Selection.ShapeRange.IncrementTop -18# .Selection.Orientation = wdTextOrientationDownward .Selection.Font.Size = 24 .Selection.TypeText Text:=Program 'end macro code End With End Sub [ 03-11-2004, 11:58 PM: Message edited by: John T. ]
  13. Thanks for that snippet bulllines. I think I'm confused about enumerate. Doesn't that mean to make a code "shortcut", such as: Set wordDoc=CreateObject("word.Application") So instead of typing the whole thing out, I can just type: With wordDoc .Visible=True etc, etc. Is that correct? I've been reading up at the MSDN library a good bit now. Mick, I'll send some code shortly. John
  14. Neat trick, macro recording! I still get the InchesToPoints error. What is it supposed to be, a constant, a integer, or a variable? with different declarations, I get things like "type mismatch","subscript out of range", "(value as integer)"? John
  15. I'm now experimenting to format WORD documents to the way I want them to look. Here's what I want: A single line of text centered at the top, that simply says "Program info" (a different color would be nice too). What is the object command to center text in word? I couldn't find anything specific in the microsoft site. Then I want it to be followed by 2 short columns, which contains essential information, such as customer name, description, program name, item number, etc. Then a seperate two columns that shows the tool list, 10 tools per column. I have the printout of the TextColumn Object here, but I think VBScript wants me to declare InchesToPoints, but I get a error message if I try to declare it as a constant or array. Then, under the tool list columns, a single line that tells the TL0 location. (or one very short pagewide column) Lastly, the rest of the page blank for a graphic of the part. Or a single column, whichever works. I think this list hinges on the TextColumn Object. John
  16. Thanks for the script, Mick. It does run under word 2000. The Word code was copied from another user here who used a sample code from you, way back when the VBscript upgrade was coming out. What are Word enums? Now to study the script, and see what I can learn, and what my next steps will be. Wish I knew more about object model programming. I'm just copying that too. John
  17. If you import a "dumb" solidworks file, try converting it to surfaces, then deleting all solids. If you prefer to work with solids, then I guess you'll have to try the various fixes involved. John
  18. Heres a combination of code I've taken from the forum. The problem is, the tool list doesn't work. It will print the header info, but not the tool list. Any ideas why? Also, do you get formatting characters in the header in Word? I do, can't seem to turn it off. John code: '///////////////// My Global Variables ////////// Dim wordDoc ' -- Start Script Call Main() ' //////////////////// ' Sub Declaration ' //////////////////// Sub Main() ' -- Add code here... Dim nCount ' number of operations Dim nToolNum ' tool number Dim nOpNum ' operation number Dim nIdx ' array index Dim nX ' for loop counter Dim arrToolNumber() ' array of tool numbers Dim arrToolComment() ' array of tool comments Dim arrToolDiameter() ' array of tool diameters Dim arrToolFluteLength() ' array of tool flute lengths Dim arrToolLength() ' array of tool lengths On Error Resume Next 'open Word Set wordDoc=CreateObject("Word.Application") If Err Then ShowString"could not get an instance of Word" ShowString"Error #" & CSstr(Err.Number)& " "&Err.Description Else wordDoc.Documents.Add With wordDoc .Visible=True .WindowState=wdWindowStateMaximize .DisplayAlerts=wdAlertsNone .ActiveDocument.Words(1).Font.Size=14 .ActiveDocument.Words(1).Bold=True .ActiveDocument.Words(1).Text="Plastic Ingenuity Operations Sheet"&vbNewLine&"Tool Number"&vbTab&"Tool Desc"&vbTab&"Diameter"&vbTab&"Flute Length"&vbTab&"Overall Length" End With End If ' get the number of operations nCount = GetOperationCount("") ' show us the number of operations ShowString "Number of operations: " & nCount ' resize the arrays ReDim Preserve arrToolNumber(nCount) ReDim Preserve arrToolComment(nCount) ReDim Preserve arrToolDiameter(nCount) ReDim Preserve arrToolFluteLength(nCount) ReDim Preserve arrToolLength(nCount) ' init the index nIdx = 0 ' get the id of the first operation nOpNum = GetFirstOperationID("") ' loop as long as there are operations to get Do ' get the tool number using the current operation nToolNum = GetToolNumberFromOperationID("", nOpNum) ' copy tool data into our individual arrays arrToolNumber(nIdx) = nToolNum arrToolComment(nIdx) = GetToolComment(nToolNum) arrToolDiameter(nIdx) = GetToolDiameter(nToolNum) arrToolFluteLength(nIdx) = GetToolFluteLength(nToolNum) arrToolLength(nIdx) = GetToolLength(nToolNum) ' increment the index nIdx = nIdx + 1 ' get the next operations nOpNum = GetNextOperationID() Loop While(nOpNum <> -1) For nx=0 To (nCount-1) WriteToWord(arrToolNumber(nX)&vbTab&arrToolComment(nX)&vbTab&arrToolDiamter(nX)&vbTab&arrToolFluteLength(nX)&vbTab&arrToolLength(nX)&vbLf) Next If askYesNo("close Word?")=mcMSG_YES Then Word.Quit 'End If If IsObject(Word) Then Set Word=Nothing End If ' Next End Sub
  19. No, I'm trying to get the tool list for whatever job I have loaded in MC at the moment. That last bit of code bullines looks like it would do what I want (haven't tried it yet). All the machinists/moldmakers here do their own programming, so they look at the program, verify, backplot, etc to see what it does and that it won't plow itself into the table, so we don't need any operation descriptions or the like, just the tool setup sheet with relevant information about the job at the top, a two column tool list in the middle, and a graphic of the part at the bottom. John
  20. I'm trying to replicate our more cumbersome setup sheet. When it comes to the tooling list, we need the tool number, tool description(5'BEM for example), tool diameter, flute length, and overall tool length. We don't need the operations list or anything. Just the tool list with the above data. Then it gets output to word. There is some other information at the top of the page input by the user, but I'm working on extracting the data for the tools first. We use up to 20 tools,but 10 or less is more common. The tool list is in 2 columns. John
  21. usually dim i dim tooldesc() toolsdesc(i)=gettoolcomment(i) is the only thing that holds a string. Reading through my vbscript book ("learn VBscript in a weekend"), it looks like I should have said dim tooldesc(19) for 20 elements. should the others (tooldiam, flute, oal) also be similarily dimensioned to 19? They are numbers, not text. Something else I've found out by poking around with VBscript. The GetToolNumber function seems to be a little crazy? Heres a little something that gives me that impression (decided to start at square one again) Dim i,Count code: ' -- Start Script Call Main() ' //////////////////// ' Sub Declaration ' //////////////////// Sub Main() Count=GetOperationCount("") ShowString GetFirstOperationID("") For i=1 To Count-1 ShowString "operation ID "&GetNextOperationID()&" Tool number "&GetToolNumber(Count) Next ' -- Add code here... End Sub In this case, the operation ID numbers were fine. The tool numbers after the first one were always 4. There are 12 tools in the job I ran this on. I notice that the documention for MC's scripting says the gettoolnumber command uses a tool ID #, not just tool number. Could that be causing the problem? This isn't a issue with gettooldiameter (and overall length and flutelength). John
  22. how about KISS code, something like the following: code: for i=1 to 20 'we rarely use that many tools tooldesc(i)=gettoolcomment(i) tooldiam(i)=gettooldiameter(i) flute(i)=gettoolflutelength(i) oal(i)=gettoollength(i) next Is it a mistake to use the variable i for both the variable name and the function? use a for-next with a different variable (n) on the outside of the functions that use (i)? I should think it would be. Bear with me. I toddling along here... John
  23. how about KISS code, something like the following: code: for i=1 to 20 'we rarely use that many tools
  24. I tried some other code just for a break-it was the timed message box that Mick posted. Instead of starting a new script, I just commented out the above "blank out" script, put Micks script above that, and it works. Just to see what happens, I uncomment the "blank out" script, run the whole thing, and the "blank out" script runs. The first tool is normal, tool number 1, etc. The rest of the tool numbers were something like 1222889 and so on for each subsequent tool. Then MC9 "generated errors" and closed after it went through the tool list. Is it possible that there was some kind of overflow killing MC9? What caused the tool number sequence to grow like that? it was just a for-next loop. John
  25. Maxopcount SHOULD be equal to getoperationcount("") according to the script. John

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