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:

vb problem in output to excel file


Recommended Posts

Hi All;

i have a problem in vbs output to excel file,when i open the excel file and use the print preview function,the graphic box become large and change to orginal size.

 

 

' -- Start Script

Call Main()

 

 

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

' Sub Declaration

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

Sub Main()

' -- Add code here...

' -- Start ScriptCall Main()

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

' Sub Declaration

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

Dim intLevelNumber

Dim strMc

Dim strOriginalPath

Dim DataPoint

Dim Cpoint

Dim datax

Dim datay

Dim dataz

'-- Loop all levels, hide all except the one the user wants

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

Dim lv_app

Dim lv_excel

Dim graphic

Dim lv_text

Dim Picture

 

Set lv_app = CreateObject("Excel.Application")

Set lv_excel = lv_app.workbooks.open ( "C:XYZ.XLS")

Dim i

Dim j : j = 1

Dim k : k = 16.5

 

For i = 1 To 100

If i <> intLevelNumber Then

Call SetLevelVisibleByNumber(i,True)

If IsDrawing() Then

SetLevelByNumber(i)

strOriginalPath = GetCurrentFileName()

'renname with LevelNumber

strMC= Replace(LCase(strOriginalPath), ".mc9", "-" & i & ".mc9")

Call RunMastercamCommand("fit")

'look for alive points

datapoint = StartDBSearch(mc_alive, mc_pointtype)

If (DataPoint = False) Then

ShowString "nil"

lv_excel.saveas( "C:XYZ.XLS")

CloseExcelFile

Exit Sub

End If

Set CPoint = New McPt

' -- Get this point x,y,z

If GetPointData(GetEntityEptr, cpoint) Then

'ShowString i

'get point data

datax=Round(cpoint.x,3)

datay=Round(cpoint.y,3)

dataz=Round(cpoint.z,3)

lv_excel.sheets(1).cells((j-1)*15+1,1) = datax

lv_excel.sheets(1).cells((j-1)*15+1,2) = datay

lv_excel.sheets(1).cells((j-1)*15+1,3) = dataz

j = j + 1

End If

strOriginalPath = GetCurrentFileName()

'renname with LevelNumber

graphic= Replace(LCase(strOriginalPath), ".mc9", "-" & i & ".emf")

Call RunMastercamCommand("fit")

' save emf file

DoMetafile graphic

'Height = 2000: Width = 1000

'Picture = LoadPicture(graphic)

' lv_excel.sheets(1).Shapes.AddPicture(Filename, LinktoFile, SavewithDocument, Left, Top, Width, Height)

Set lv_text = lv_excel.sheets(1)

lv_text.Shapes.AddPicture graphic, False , True , 0,k, 200, 160

k= k + 247.5

 

' save file

Call SaveMCAs(strmc,True)

Call SetLevelVisibleByNumber (i,False)

End If

End If

Next

Call RepaintScreen(True)

'End If

ShowString "complete"

lv_excel.saveas( "C:XYZ.XLS")

lv_excel.Close

lv_app.quit

Set lv_app = Nothing

End Sub

'entity serach

Function IsDrawing()

Dim Ret

Ret = StartDBSearch(mc_alive, -1)

IsDrawing = Ret

End Function

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

' Function Declaration

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

Public Sub ShowAllLevels

'-- Loop all levels and show them

Dim i

For i = 1 To 255

Call SetLevelVisibleByNumber(i,False)

Next

End Sub

 

 

thanks

Maks

Link to comment
Share on other sites

code:

 DoMetafile graphic

'Height = 2000: Width = 1000

I would look here may need to put control in here to allow the user to isze it to there needs. That Seems very big but since I can not test the code at home will have to wait till tommorrow if I go in to change out parts or for one of the VB kings like Rekd, Chris, Mick or others.

 

For our Excel set-up Sheets I use Clipboard. Do a search and There is a quick a easy script for doing Scren to white open up clipboard then change screen back to black again. rekd help me out with that one it is a real time saver.

 

HTH

Link to comment
Share on other sites

I've seen Excel have that problem with EMFs and it is quite weird. Excel appears not to like embedding resized EMF files into a spreadsheet. But BMPs seem to work ok. Try replacing this:

 

code:

'renname with LevelNumber 

graphic= Replace(LCase(strOriginalPath), ".mc9", "-" & i & ".emf")

with this:

 

code:

'renname with LevelNumber

graphic= Replace(LCase(strOriginalPath), ".mc9", "-" & i & ".bmp")

And replace this:

 

code:

' save emf file

DoMetafile graphic

with this:

 

code:

' save bmp file

Call DoBitmapfile(strOriginalPath, graphic)

Hope this helps.

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