Catia Screen Capture Code - vba

Can someone help me with a code for capturing a 250X250 pixcel screen and copying it into clipboard. I would like to paste the image into an excel i can code that part. I have no clue where to start. I have made a code till reframing on the a point where i need the macro to capture.
Dim objviewer3d as viewer3d
Selection1.search("Name="+Textbox1.value+"*,all")
Caita.startcommand("reframe On")
Catia.refreshDisplay=true
Set objviewer3d=catia.activewindow.activeviewer
Objviewer3d.viewpoint3d.zoom=0.017
objviewer3d.update
This is the code i have written. I need the capture code. I Have no clue how to do that. And Last thing I know code to capture full screen and capture to file code. I don't want that.
Thank you

The CATIA method which captures the current window to a file is Window.CaptureToFile:
CATIA.ActiveWindow.ActiveViewer.CaptureToFile catCaptureFormatJPEG,"C:\Temp\Capture.jpg"
This captures the entire window, so to make it 250x250, set the ActiveWindow.Height and .Width to 250 before capturing the image. Then set it back afterwords to it's original size only. Alternatively you can resize the image after you insert it into Excel as a shape.
If you want the tree off you can also call ActiveWindow.Layout = catWindowGeomOnly

Related

Coyping grouped images as picture and crop it in ppt via vba

I have a problem to get a certain amount of shapes in ppt to a certain format. I generate them via nprinting and they are already grouped properly. The problem is that I can´t crop them once their grouped. If they are not grouped I can address each of them individually and crop them the way I want. I need them in picture(u) format in order to be able to crop them. My approach was to cut them and insert them again but as picture. Unfortunately I wasn´t able to cut and paste them via vba with the code below. Does anyone have an idea how to solve this?
Dim myDocument As Object
Set SlidePPT = objPPT.Presentations(FilePPT).Slides(7)
SlidePPT.Select
myDocument.Slides(7).Shapes.SelectAll.Group
Selection.Cut
myDocument.Slides(7).Pictures.Paste
myDocument.Slides(7).Shapes(1).PictureFormat.CropBottom = 200
The alternativ I had in mind was to crop it first and Group it then, but this seems not to work either.
edit: Okay, it seems that the problem with my alternative approach is, that my code just selects all of the shapes but does not group them. Any ideas on that?
Solved it. i just needed to add the range.
myDocument.Slides(7).Shapes.Range.Group

Adding a background image to a particular cell

I tried to insert the background image using following code:
Pic = "C://Picture/Logo1"
Activesheet.SetBackgroundPicture Pic
This inserts the picture to full sheet but I want to add it to particular cell or a range of cells. Please help
As far as I know excel doesn't support appending the image to a cell (with or without VBA).
The background of a single cell supports colors/gradients/fill-patters, but not the pictures.
It is possible however, to "place" the picture (shape) object with the same width and height right above the cell and make it locked and move around together with the cell if somebody attempts to resize cell widths. I personally wouldn't go that way, too much to code and too much risk of breaking the structure.

PowerPoint: Repeat text on every slide

I'm working on creating a PowerPoint template for daily class presentations. In the template I'd like to have a hunk of text that is prominently displayed on the first slide and which repeats at the bottom of the subsequent slides at the bottom in a smaller size. The text will change every day.
The ideas I've had so far:
Use a text field. As far as I can tell, PowerPoint doesn't have anything like a text field that can be dynamically set.
Use a footer - this works and I can modify the master to get the look I want, but I'd really like to be picking up the value of the text from the first page so that edits would be automatically applied and to save the initial step of setting the footer.
Using VBA - I'd be willing to give this a shot, but I've never used VBA and the learning curve seems steep so it would be nice to know if the idea is feasible in VBA.
Can this be done? How would you approach it?
Here's an example of what I'm hoping to be able to do. Ideally the solution would work on both the Mac (2013) and Windows (2016) version of PowerPoint.
You can connect your presentation with an excel file. And running the code in the ppt would pull out the text in the excel file and update the titles instantly.
Create a presentation with a textbox with some temporary text. Put the below code in ppt. save as pptm.
Sub AddMotionPath()
Dim Temp As String
Excel.Application.Workbooks.Open ("D:\Users\Desktop\Book1.xlsx") ' update the path of the excel file
Workbooks("Book1.xlsx").Activate 'activate the file
For p = 1 To 4
Temp = Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("B" & p + 1).Value ' Column B has the titles
ActivePresentation.Slides(p).Shapes(1).TextFrame.TextRange.Text = Temp ' this updates the titles from excel to ppt slide
Next
Excel.Application.Workbooks("Book1.xlsx").Close False 'closes the excel file
End Sub
Let me know if this works for you. You can update the excel file and run the macro in ppt. The text in the slides will be updated automatically.

VB.NET: Preserve image metadata when moved to clipboard as an image

Visual Studio 2010, .NET 4, VB.NET
Hello,
I am writing a little program to convert LaTeX snippets to images which can be pasted into whatever program one can paste images into. It's working alright but the next obvious step is to include the source LaTeX code as a piece of metadata in the image so that the results can be modified without having to retype everything.
I have succeeded in adding a title PropertyItem with the latex encoded as an ASCII byte array as its value (id=800, type=2, value=System.Text.Encoding.ASCII.GetBytes(codestring)). I verify that the PropertyItem is really there before trying to put the image on the clipboard.
Then I do Clipboard.SetImage(myImage). The result is all of the PropertyItems are removed (my title plus anything else that was there)! I check this by doing MsgBox(Clipboard.GetImage.PropertyItems.Count.ToString) which gives zero.
This makes me very sad. Anyone know what's up?
Thanks in advance!
Brian
Update: I have figured out how to move the image onto the clipboard and then back off while preserving the PropertyItems like so:
Format = DataFormats.GetFormat(GetType(Image).FullName)
Dim dataObject As New DataObject
dataObject.SetData(Format.Name, image)
Clipboard.SetDataObject(dataObject)
Dim copiedImage As Image = CType(Clipboard.GetDataObject.GetData(Format.Name), Image)
This way, the copiedImage has the same PropertyItems as the original. However, new problem:
Other programs don't recognize what's on the clipboard as an image anymore, which defeats the whole purpose. I.e., if I put an image on the clipboard this way, when I try pasting into some context that accepts pasted images, nothing happens.
What to do?!
I believe the Windows clipboard image has no metadata. If you change the format of the image to add metadata, it is no longer a clipboard image. If the other programs can accept it, you could copy and paste the image file (instead of the image) to the clipboard, and the metadata will of course be intact when it's read by the target app.
Have you tried Clipboard.SetData or Clipboard.SetDataObject? SetImage only copies the image in bitmap format, so I am not surprised that it strips the property items. You might try:
Clipboard.SetData(DataFormats.EnhancedMetafile, myImage)
or
Clipboard.SetData(DataFormats.MetafilePict, myImage)

merge excel cells via VB.NET without asking when every cell has a value

I have a VB.NET website and I am organizing some data in excel file.
I need to merge cells which have same data in excel but everytime I try to this operation, program stops and shows this notification:
I don't want to see it and I want program to continue without asking. Is it possible, thanks..
I assume you have something like
Dim oXL As Excel.Application
somewhere in your code. If so, then all you need to do is put the line
oXL.DisplayAlerts = false;
before you try merging, and then set it back to true afterwords for safety.
If not, please post some of your code and I'll help you out further. This DOES work, though. I've done it before.
If you were to do this manually, and answer OK, then all the data except the data from the top-left cell would be lost.
Why do you not clear the other cells before merging?