Data map display via VBA macro

Hi all :smiley:

I'm currently trying to implement a function in a macro but I'm stuck... I therefore appeal to your knowledge!
I wish I could open the data map of a PDM file via a VBA macro but the result I get leaves me perplexed ahaha

Here is the piece of code we are interested in:

Global File As IEdmFile13
Global Folder As IEdmFolder10
Set Folder = vault.GetFolderFromPath(fs.GetParentFolderName(CheminFichier))
Set File = Folder.GetFile(fs.GetFileName(CheminFichier))
Dim CardView As IEdmCardView63
Set CardView = Folder.CreateCardView2(File.ID, 0, 400, 100, , 253)
CardView.ShowWindow (True)

And the result is as follows...

It shows the data card half transparent and when I hover the mouse over it, it disappears!
Help on the function: CreateCardView2

If anyone has an idea of how to do it? Whether it's with this method or another, I'm all for it!

Thanks in advance :wink:

Hello

By testing quickly, I think that the function only displays the map without access to it from an editing point of view, so you have to "place" it in a window that has a background (basically on a userform with a gray background it appears normally, otherwise in the macro editor it appears in transparency)

1 Like

Ah, I see! But how do you "install" it in a UserForm?!

Or by creating a userform that contains buttons and calls the snippet of code.
Or put it directly in the procedure for activating the form.
On the other hand, you need to retrieve the height and width information of the card to resize the form correctly and display the whole map.
In the help of the api if you are in vb#net it is this piece of code:

' Get the size needed to display the card 
        Dim width As Integer
        Dim height As Integer
        view.GetCardSize(width, height)

Otherwise roughly in vba:

Private Sub UserForm_Activate()
Dim File As IEdmFile13
Dim Folder As IEdmFolder10
Dim width As Long
Dim height As Long
Set vault = New EdmVault5

vault.LoginAuto "_TDM_PROD", 0
CheminFichier = "C:\xxx\xxx"
Set Folder = vault.GetFolderFromPath(CheminFichier)
Set File = Folder.GetFile("xxx.SLDPRT")
Set CardView = Folder.CreateCardView2(File.ID, 0, 400, 100, , 253)
CardView.GetCardSize width, height
UserForm1.width = width + 80 'à affiner pour la largeur
UserForm1.height = height + 10 'à affiner pour la hauteur

CardView.ShowWindow (True)
End Sub

Even following this code it still shows me the data map in transparency in the middle of nothing and not on the UserForm :confused:

Have you put it in the UserForm activation procedure?
You must also call this form in a main module by Userform.Show

Yes, in my first function I perform:

UserForm1.Show 

and in UserForm1 I have the following code:


Public Sub UserForm_Activate()

Dim l As Long
Dim h As Long

        Set Folder = vault.GetFolderFromPath(fs.GetParentFolderName(CheminFichier))
        Set File = Folder.GetFile(fs.GetFileName(CheminFichier))
        Dim CardView As IEdmCardView63
        Set CardView = Folder.CreateCardView2(File.ID, 0, 400, 100, , 253)
        CardView.GetCardSize l, h
        UserForm1.Width = l + 80
        UserForm1.Height = h + 80
        CardView.ShowWindow (True)
End Sub

VBA code in Excel or SW? (I tested on Excel)

VBA under SolidWorks!

I'll test a little later and will give feedback

1 Like

Thank you @Cyril.f ! Not the first time you manage to unblock me with a macro story ahaha :slight_smile:
I'm going to dig on my own too and I'll make a return too if I find the solution!

:wink: I've coded quite a few whether it's on SW/PDM/Excel/Word/Outllook so when I can help.

So after testing, on SW it's just a problem of declaring variables. Excel does well without declaring the CardView variable.
In the SW api you have to add:

Dim CardView As IEdmCardView63 'ou IEdmCardView64 ça dépend de la version majeur de PDM
1 Like

it finally seems to show it to me!! I had declared the variables but within the procedure of the UserForm_Activate ... by putting it outside the instruction it shows me it!
I still have to dig because on my side it displays it as an image in the UserForm :confused: I can't modify or do anything on it

Yes, that's the problem, the map displayed is only a "dead" object. You have to look in the options and it seems to me that you have to run other functions to then apply the changes

1 Like