CATIA points and Excel: there and back again

Milton Hartung

CATIA points and Excel: there and back again

I've seen several solutions pertaining to getting points coordinates to and from Excel spreadsheets and never found anything I personally liked that well.  I would like to offer everyone two macros of my own design, I believe you will enjoy them.  They are written in MS VBA from within CATIA.  Let me know what you think.

Rename the txt files to bas and you can import them into a VBA project in CATIA.

1. Export points to Excel:
The first macro asks for a Set with points, or uses the one preselected if it is not empty.  Next is the option to export in 3 or 4 column format (with or without element names).  Next, Excel asks for the range to put the XYZ values into.  If you have, for example 200 points and select a range of 40 rows, you will continue to be asked for ranges until all points are used, or you cancel (multi-page report, etc).

2. Import points into CATIA:
This macro will create blank parts if one is not open/active.  Excel will ask for the range with the XYZ coordinates, and CATIA will build points.  Blank or incomplete rows are skipped.

EDIT: Link added, hopefully it is easier to find this way

Download PointsMacros.zip

Jay Evans

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Milton -

I am trying to run the first script to export points, but I am getting an error. I am no expert in scripts, so could you please help? Here is what I have done:

Copied the text from your first file. Went into catia, went to tools, macros, created a new macro and chose MS VBScript as the language. I pasted in the text, and saved, and tried to run the macro and get this error:

Execute the script "export points.catvbs".
The scripting engine for MS VBScript has reported the following error:
Source: Microsoft VBScript compilation error
Description: Syntax Error
Statement: On Error GoTo ErrHandler
Line: 11
Column: 18



If you could provide any help that would be great. It would be very beneficial to be able to export point locations to excel or text files. Thanks.

--Jay

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Sorry, I wasn't very clear I think. These MUST be imported into a VBA project. To my knowledge this limits you to Windows-based I'm pretty sure. Anyway here are the steps that should hopefully lead to everyone's success.

1. Within CATIA, click Tools -> Macros->Macros.
2. Click the 'Macro libraries' button.
3. Under 'Library type:' choose 'VBA Projects', then click the 'Create new library' button. Enter the path and file name you want here.
4. Close the 'Macro Libraries' window.
5. Within CATIA, click Tools->Macros->VB Editor.
6. Select the new Library from the tree on the left side, then click File->Import File.
7. Set 'Files of type' to All *.*, and browse and select to where you saved the .txt files from me. Pick one and repeat 7 for the other.
8. Lastly, before exiting VB Editor, click Tools->References. Find 'Microsoft Excel 11.0 Object library' and check it. If it is Excel 9 or 10 or 12 or something, it should still work fine. 11.0 is just what is with Office 2003.
9. Save the VB Project and close the Editor.
10. Now in Tools->Macros you can run these modules you just imported. If you have CATScript and Catvbs macros that you need as well, simply change the 'Current macro library or document' to the Macro folder you had defined before.

Look back over my original post for some usage ideas. And let me know if you have other questions.

Jay Evans

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Milton -

Thanks so much for your detailed explanation. The import points works, however I still have trouble with the export as follows:

On Winxp 64 bit, R17sp8:
The macro runs just fine, but always exports points as 0,0,0 coordinates.

On Winxp32 bit, R17sp7:
The macro attempts to run, but comes up with an error (something like Get mo Sel not valid object) I'll have to test again to see the exact error.

If I could just get the export points working this would be perfect. Your code is great an well-commented (unfortunately I have little experience with vba so it is hard for me to debug).

Only other thing, the points are in mm. (This is not a huge deal, as I can convert them in excel before or after importing/exporting) but it would be nice not to have to do this, if there is an easy way to change it.

Thanks again Milton.
--Jay

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Jay,

Thanks for your kind words. I did try to make these macros in good form, but they are admittedly written with only one environment in mind, our own. But a couple simple changes should get this going for you.

First, regarding Win64, I saw this post the other day:
http://www.coe.org/Collaboration/DiscussionForum/ActiveDiscussions/tabid/210/view/topic/forumid/10/postid/113750/Default.aspx
As excited as I have been about 64-bit, it just keeps disappointing. But that is a WHOLE other topic haha.

Regarding your error with your 32-bit install, I'll see what I can come up with. Let me know the full error message especially line numbers if it says, and if it is in the ExportExcel or ExportText, and if possible explain at what point it fails (immediately, after asking delimiter, etc).

On to converting mm to in. CATIA is storing these as mm regardless of your params and measures. Just start using mm! Ha, seriously though, the following few lines will fix you right up, and convert right in the macro.

ImportFromExcel, lines 81 - 83 add right before the closing paren:
* 25.4

ImportFromText, lines 123 - 125 AND 132 - 134 add right before the closing paren:
* 25.4

ExportToExcel, insert these lines at line 115
'convert from mm to in
coords(0) = coords(0) / 25.4
coords(1) = coords(1) / 25.4
coords(2) = coords(2) / 25.4

ExportToText, insert these lines at line 91
'convert from mm to in
coords(0) = coords(0) / 25.4
coords(1) = coords(1) / 25.4
coords(2) = coords(2) / 25.4

I will probably add a proper fix to these as soon as I can, like a prompt for mm/in or something easy to switch, to make it more useful to more people. Keep me posted Jay, we'll make it work!

Alasdair Ryder

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hi Milton,

Just set up and installed your macros & just wanted to say many thanks. They've worked a treat and saved me a lot of effort.

Gratefully,

Alasdair

Jay Evans

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
It must have been an error because it worked fine in R18. I then upgraded R17 to SP8 and it now works fine. I also incorporated the mm to in conversion and both the import and export to excel work great!

Now if only they would fix 64bit version...

Thanks a ton Milton. This is a really nice program to have.
--Jay

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Milton - works fantastic. Just did a test and exported over 2200 points. Thanks much!

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

To All,

Taking to mind the possible needs others might have for a Point Coords macro, I have redone my previously posted code.  The attached is a complete CATVBA project.  These new macros roll the Excel and Text file macros all into one GUI.  There are checkable options here instead of multiple question pop-ups as the program runs.  By editting the UserForms, others can set their own default options very easily.  Options include:

  • Import/Export to open Excel doc OR text document
  • Scale values to mm, in, or by a custom scale
  • Keep point names while importing or exporting
  • Select the precision
  • Choose the delimiting character while importing or exporting

To use this macro project:

  1. Copy the CATVBA file to a network location.
  2. On the CATIA Macro dialog, click Macro libraries.
  3. Click Add Existing Library
  4. Browse to it and click Open
  5. Close the Macro Libraries dialog
  6. Now in the CATIA Macro dialog, you can select the new library from the drop-down box.
  7. Click Edit to launch the VB editor
  8. Click Tools -> References and choose the Microsoft Excel Object Library and click OK.

If you have issues, bugs, requests, or kind words, please let me know!

Download PointsMacros.zip





John Stick

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi LUENYAR,

Very nice this macro !
Only one request: to retain (to keep) path of the last used file.

Thanks,
John

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Ah, very good idea!  Thanks for the inspiration!

These are updated so ALL paths, options, and values are rememberd via the Registry, per user it looks like based on the location (HK_USERS\S-1-5-21-...\Software\VB and VBA Program Settings\).  The only thing not remembered is the filename part of the export filename path.

I look forward to your feedback!

Download PointsMacros.zip

Jay Evans

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Milton -

The last two iterations are great (with the prompt), but I now get an error and it won't finish running.

Trying to export points, I get the first prompt so I set all my options, then I get the prompt to select a geometric set. As soon as I click on the geo. set, I get the error:

"Unexpected Error 438 (object doesn't support this property or method)"

This is on winxp 32bit, R17 SP8. I made sure to add the tools->references->excel link library and follow the other steps as you suggested.

Any idea what it could be? I am really excited to get this working.
--Jay

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Me again!

Someone requested adding support for exporting the coordinates relative to a selected axis system. So, I will have a new version up very very soon. Right now, I've only added support for exporting with an axis. Could those that would use this functionality tell me, would it be useful to add similar functionality while importing points?

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

This is updated to include the option to export your point values based on a selected axis.  Thank Cliff Johnson for the math dealing with the transformations!

The import functions don't yet do anything with a selected axis, possibly this will be added later.

Hope it is useful!

Download PointsMacros.zip

Vien Ba Nguyen

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Luenyar,

I do not have VBA library build into my CATIA software. The VBA library when I go to Tools>Macros>Macros Libraries isn't exist. The VBA editor isn't available either.

I made a search on google about adding VBA library to CATIA and found nothing but run around and useless methods for which I do not understand.

Some suggesting that I have to register CATIA as Microsoft embedded OLE server. I do not know what that's mean.

I am in charge of 3D drawing for an aircraft design and in desperate need of finding a way to enter airfoil coordinates from an excel spreadsheet into CATIA.

So far the only method I know is plotting point point and it takes forever. There are over 70 coordinates per airfoil and I have to continuously drawing new airfoil design. There has got to be a quicker way and I found it by employing the method of macros.

My dilemma is that my CATIA software does not contain VBA library and script. Is there a way to add VBA library to CATIA.

Thank you in advance.

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Is your CATIA installed on AIX or other non-Windows PC? Unless I am mistaken VBA is only available on Windows. If you are on Windows and don't have VBA in CATIA then I really don't know, I didn't know you could install without VBA support. I might have some CATScript macros that import from txt file if they would help?

Vien Ba Nguyen

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Luenyar,

My operating system is window vista 32 bit. My CATIA software is V5R17. I do have microsoft office softwares installed and that include VBA.

I have no idea why the VBA library doesn't showing up. If you do have some CATscript macros that can help me import point coordinates from an excel spreadsheet that would be so helpful.

Thank you

Vien Ba Nguyen

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Luenyar,

I've found the answer. VBA library doesn't install during CATIA instalation. You have to go back to the CATIA CD's directory and open up the VBA folder. In there there's an executable file called VBA6.msi. Run that and problem solved.

Thank you for your help though. Your macros look great!!!

Sandip Gaikwad, Engineer

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

its working

Jay Evans

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Milton -

First I just have to say a big THANK YOU as this macro works great and will probably save me much time and frustration. I very much appreciate your contributions.

The new feature to use an existing axis system is WONDERFUL!

I do have two questions:
1. How hard would it be to have it only output x and y coordinates and just ignore the z-value?

2. I still can't get it running under winxp 64 and 64 bit catia. I go thru the script just fine with all the prompts, and one of 2 things happen:
a. if I DON'T use another axis system, it runs fine but the coordinates of the point are always 0,0,0

or

b. if I try to use another axis system, instead of the "success" message I get the error: "Points (0) raised an unexpected error 1001 (Zero length vector cannot be normalized)."

This is a brand new catpart with nothing in it but a test point, and v5R17 SP8. I also tried with same result with R18 SP4.


These are not big issues by any means but I thought I would put it out there in case there is an easy fix. Thanks again Milton (and everyone who contributed).
--Jay

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
I don't have any experience yet with VBA on the x64 OS. A couple of weeks ago we got 2 new workstations with Vista x64 on them so I'll have to experiment when I can pry people off of them heh.

If you want to modify these macros to output to specific forms and only want XY I think you can just change a couple things in the ExportToExcel function. The first thing is the section that gets your option to export the point names. Reduce each by 1

If (tfUseNames = True) Then
expectedColumns = 4

Paul Ilenda

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Wow...

I just imported 1500 points and didnt have to sit there and manually click on each 1 to create a point. This macro will save me lots of time!

Tell me what kind of beer you drink and what your ship address is, I'll send over a microbrew from Atlanta.

THANK YOU!!

Panagiotis Davaris

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi,
I am using Catia R18 and I tried the vba macro from Milton without luck. I execute the macro and I get no reply!
Does any body have any recommendations.

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

All I can really suggest are the steps here to get it into CATIA, then follow the step regarding 'Microsoft Excel 11.0 Object library' by changing to the version that shipped with your install of Microsoft Office.  Other than those steps I probably couldn't troubleshoot most usage problems.  I am using with these conditions:

Windows XP SP3 32-bit, Microsoft Office 2003, CATIA V5R18 SP6+Supplier Integration Hotftix.

Sorry, and good luck.

Panagiotis Davaris

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hi,

My level is R18 SP4, office 2003. The strange is that when I execute the macro nothing happens. I followed all the steps and I checked 'Microsoft Excel 11.0 Object library' (attached image).


Very strange! Doesn't work also in R19!

Thank you very much.

Attachments

  • 11125112277336.zip (73.7k)

Tim Linke

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)


This application worked GREAT but now gives me a "compile error, can’t find project or library". In checking Tools> Reference in the VB editor if shows the following library as MISSING: CATIA V5 EMOXx CATIAv5Intergration Object Library. The location of this library is supposed to be C:\Programs\DassaultSystems\B17\intel_a\code\bin\mx…

All the other libraries referenced by the macro are in C:\Programs\DassaultSystems\B18\... think I just need to point the CATIA V5 EMOXx CATIAv5Intergration Object Library reference to the B18 file that replaces the C:\Programs\DassaultSystems\B17\intel_a\code\bin\mx… file.

I cannot find the a file in B18 named something like CATIA V5 EMOXx… or starts with mx. Would you know wha the new/correct file in B18 would be or haven't you had any trouble like this running in v18? If you don't think this is the problem let me know.

Thanks

TL

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

@Panagiotis:
Have you tried without 'Microsoft Office 12.0 Object Library'? Its the only other thing I can recommend, as I do not have it checked in my case.

@trlinke:
These plus our other macros I've created still worked fine on migrating to R18. On scanning my references, I can't find anything similar to the specific file you mentioned, nor have I found anything named similar in /code/bin. I can only offer the suggestion to try unchecking it? I wish I could offer more help, but like I said my CATIA administration experience is long (7 years), but narrow (only my current company).

Maybe someday I'll break all my macros and convince the boss I need CAA or whatever to fix them heh. Perhaps a proper CATIA function would work for a wider audience? I wish I knew =P

@x64 users:
I forgot to mention, that I did a couple small brief tests on the x64 machines we have now (running Vista Business x64 and with Office 2003). As far as I could tell, both the import and export to excel worked fine. It might make a difference that I've installed the x86 CATIA code instead of the x64 based on both bad personal experiences and advice from others.

Good luck, sorry I can't be more helpful.

Tim Linke

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

@LUENYAR:  It dosen't seem that my reply got added to the thread so I wanted to say thanks for your recomendation.  I thought I had tried unchecking the MISSING library but when I tryed it again, the script worked fine.  Thanks again for the recomendation and for creating the macro to start with.

TL

John Gustaf Almquist

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hi Milton!

Your macro is brilliant! It has saved me tonnes of work. Thank you!

I have however made feeble attempts to modify it. I could really benefit from a function where the imported points overwrite the ones already in the part (with the same names) so that they can manipulated in Excel. Do you know if this possible at all or if CATIA wont allow it?

In my dream scenario I would like the to be able to change the sets of points (stored in diiferent tabs in Excel) in the same manner as when you change Parameters using the Design Table function. Do you know what I mean? I guess will have to work on this for a while... =)

Regards, John

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Probably possible. I guess you would have to be sure you are naming the points uniquely, then during the creation loop, check for an existing point with that unique name and update it if it already exists, else make a new one. There is similar code in the macro already that, based on the 'Use Separate Sets' selection on the dialog, will search for a GSet named 'Import Points' and use it if it exists, else creates a new one. So it should be possible as long as you don't have 2 points named Point.15 for example. They'd have to be unique I believe. Good luck!

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Milton!

I am new on this forum and I could really used the macros you are talking about but I don't know where to find them in the website.

Thanks,
Javques

Mike Despenza

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Milton,

Great macro, I started with the original script from awhile ago on my old system. Then I upgraded to the latest and greatest with the GUI, and my 64 machine. Export only gives me 0,0,0, but I need the import function. The first three times I ran the import function (from Excel and a .txt) it worked great. The last time it worked I used a custom delimiter, now i get this error before the GUI even "pops-up":

"Run-time error '2110':

Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."

Debug jumps right to the Private Sub optExplicitDelimiter (ln63) but I have no idea how to fix it, or build in exception handling.

Thanks in advance for any help you can offer.

 MD

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
I can't duplicate, but I did find a different problem with it always loading the value from registry over what was typed. Oops heh.

What did you use for the delimiter? Perhaps I didn't test enough possibilities to find one that broke it. In the mean time, can you comment out line 62:

txtExplicitDelimiter.SetFocus

and/or clear the related registry keys at:

HKEY_CURRENT_USER\Software\VB and VBA Program Settings\CATIAPoints\Import\

That sounds like it is causing the problem, but I can't think why because I didn't think that sub should be calling unless you click the checkbox. I will look at it closer when I get a minute, and post any updates if I find a change is needed.

As for the x64 issue, I really don't have any ideas what is different in the x64 code that causes the 0,0,0 issue. Like I said before, I can run the export on x64 machine with x86 CATIA code installed with no issues.

Mike Despenza

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Opps, I was trying to use tab, but i just hit the tab key in the Custom Delimiter box. When i checked the reg key the value of Custom Delimiter was a tab. Clearing the reg key fixed the problem.

For future reference should the input be vbTab or \t?

I also noticed it loading the value of the reg key when the checkbox is clicked, despite what's been typed in the box.

Works like a charm again, I especially like the Excel input feature. Thanks.

MD

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hello Milton,

It seems that the import macro works fine but I would like to know how the excel spreadsheet used to export data from has to be filled in. Do you have a template of an excel spreadsheet which works? If yes it would be very nice of you to forward it to me.

cheers

Jacques

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
You can export to any range that has 3 columns (or 4 with names). It should be flexible enough for you to export to any form you are using, or even just a blank worksheet, as long it has 3 columns. You can import values from any range that you can select 3 columns. Even if you have 200 points, you can do multiple ranges of 40 or 50 and have multiple pages. So, this macro is not limited to any template, you should be able to use anything that works well for your company.

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Again,

when i try to import data from an excel spreadsheet which is made of 3 columns (X, Y and Z), I get this error:

"
Invalid Point encountered. Continue?

Contents of invalid point file line:
##### (different symbols)

Expected delimiter: .

"

Do you know how to avoid this error?

Thanks

Jacques

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
It sounds like you are trying to use Import From File option instead of Import From Excel option. Import From File only can parse text files (extension doesn't matter). Open the Excel document, run with Import from Excel checked, and then you will select a range in the worksheet.

If for some reason you cannot use the Import From Excel option, you could save your Excel document as some kind of delimited text file, and then import it.

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Thank you very much Milton.
The macro works perfectly well and saved me a lot of time in my work.
I still have something to ask you. I could really use the same function JIGGA was talking about, i.e. a function where the imported points overwrite the ones already in the part so that they can be manipulated from an Excel spreadsheet. I have tried to create a function at the level of the creation loop in your macro (around the Set newpoint function) but I am a beginner in VBA, and even more in VBA for Catia so I could really use a little help on this one...

Thanks again

Jacques

Juergen Bittner

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hello everybody

I have to import in Catia V5R17 point coordinates form a text file.

In my TXT file I have  the XYZ coordinates, see attachment.

I followed the steps from LUENYAR see below:

1. Within CATIA, click Tools -> Macros->Macros.
2. Click the 'Macro libraries' button.
3. Under 'Library type:' choose 'VBA Projects', then click the 'Create new library' button. Enter the path and file name you want here.
4. Close the 'Macro Libraries' window.
5. Within CATIA, click Tools->Macros->VB Editor.
6. Select the new Library from the tree on the left side, then click File->Import File.
7. Set 'Files of type' to All *.*, and browse and select to where you saved the .txt files from me. Pick one and repeat 7 for the other.
8. Lastly, before exiting VB Editor, click Tools->References. Find 'Microsoft Excel 11.0 Object library' and check it. If it is Excel 9 or 10 or 12 or something, it should still work fine. 11.0 is just what is with Office 2003.
9. Save the VB Project and close the Editor.
10. Now in Tools->Macros you can run these modules you just imported. If you have CATScript and Catvbs macros that you need as well, simply change the 'Current macro library or document' to the Macro folder you had defined before.

The result was this error message:

COMPILE ERROR

SYNTAX ERROR  (and all the xyz coordinates are shown in red)

I think the issue is with the VBA script. Could somebody show me how to write this script the right way with maybe a screen shot, etc.

Please help.
Thank you all,

Juergen

Attachments

  • 122551836994.txt (1.8k)

Juergen Bittner

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hello Milton,

When I follow your steps I get always a CATVBA with all the coordinates shown in red.

I think the problem is how the scriped is written (see the command I made just a few minutes ago).

Would you be so nice to help me out?

Thank you,

Juergen

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

So, this is my idea for accepting TAB and pretty much any character or string you might be using as a delimiter.  The combo box has choices for TAB which uses vbTab, and SPACE which is just a single space, and comma and semi.  Then you can also type a character or string as well.  I quickly tested it with '~~~' and '^$#' which both work fine, so you could use probably anything that isn't used to represent the values themselves [numbers, single dashes, etc].

Download PointsMacros.zip



Juergen Bittner

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hello Milton,

you are my hero!!!

Your macro is great and it worked best with a Excel file, I imported up to 15000 points with no problems.

Regards,

Juergen

Tolga Guzel

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
I am supposed to be new in this forum.
How is the macro downloaded? I couldn't find in this topic.

Thanks a lot

Haridas PT

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

See the last line for the reply dated 03 Feb 2009 07:46 AM. You will find a .zip file. ight click and save the file.

 

Tony Nhu

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

LUENYAR:

May I have a copy of this VBA project to export points from Catia?

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi,
I have installed the macro librairy posted on 03 Feb 2009 07:46 AM. (12332307833.zip)
I can export points to a txt file... it works perfectly, but I can't import points. I get the following error:

"Macros raised an unexpected error -2147467259 (Method 'Search' of object 'Selection' failed)."

I get the same message on two different pc (one with Excel 2007 and the other one with Excel2003)

Can someone help me out?
Thanks,
Dom

David Haag

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hi Milton,

I have also installed the VBA Project in my CATIA V5-R18 in Windows XP 32 OS.

Some of the macros work like the rename elements, but when I choose the import or export points macros nothing happens, no pallet, no exported point list.

Is there something I have missed.

Any input would be a great help.

Thanks,

David

Krzysztof Bialek

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

I have the same problem as DavidHaag has.

Windows XP Pro, CATIA 5.18 SP5, VBA.msi installed, Microsoft Excel 12.0 Object Library selected

/Krz

Krzysztof Bialek

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

I have more info about the problem.

If I start macro in normal way (Alt+F8, select ExportPoints, Run) then nothing happen.

But if I Choose ExportPoints then Edit and run it from VB editor then... it works.

Then the problem is that if I export to Excel file then the coordinates are 1000x bigger. If I use 1000 unit in the form then the coordinates are 1000x smaller then real.

But if I export to txt then coordinates are OK.

/Krz

Pawel Dobrowolski

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
In your case there could be problem with regional settings.
If macro interpret . as dot point (American stanadard) and you use European standard , as dot point, you can get wrong number.
Comma , is used to define thousands in American standard.

If you use for example Polish regional settings, you can try to change them to American or British and check macro.
This can help. However, I'm not sure because i didn't looked in code.
Note that Excel is using Windows regional settings to define numbers.

Pawel,

Krzysztof Bialek

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Yes, changing regional settings to English (US) helped with the incorrect values in Excel. Thanx.

But problem with running the script in normal way still remains. It's working in 5.16 but not in 5.18.

Even if I start it from VB editor and use export to Excel then after script adds coordinates into Excel I get erro message in VB editor:

Run time error '5':
Invalid procedure call or argument

and if I click on "Debug" it shows that the problem is in line number 323:
AppActivate "CATIA"

What can it be?

(I have English Windows XP 32bits)

/Krz

Ian Spiller

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
I keep getting the following error: "Points Raised an Unexpected Error (6) Overflow"

I have a very large point file ( Roughly 300,000 points) in a .txt file. Units are in standard 1 inch, and they are set out to 6 decimal places.

Is the decimal place definition causing the error or the mass number of points?

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

This was due to an oversight on my part.  The counter variable in the macro was declared as Integer.  I've changed it to Double, so now you should be able to import as many points as CATIA and your workstation can handle.  This is the only change from the last posting.  Enjoy!

We're using MSO 2007 now by the way, so you may also have to change the References Excel xx.0 entry.

Download PointsMacros.zip

Attachments

  • 15672088363.zip (369.7k)

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hi Buddy ,

 

Your works looks fantastic but I am not able to see your attachments. Can you make the links visible? I am a beginner and totally lost in this conversation. Everyone is talking about the macros but I don't find them anywhere. Please help. And how can I install them?

 

Thanks

Nile

 

Andy Southern

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi!

This Macro is great! everyone in the office looked at me after I imported a couple of hundred points and exclaimed my delight!

Is there a way to import the points and keep them referencing the original CSV/Tab text files?

Thanks,

-Andy

Hrishikesh Mandyam

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Milton and all the others

I just found the vba projects and added them to my library. I want to know if this works for ASCII files? I have a file which potentially contains more than a 100000 points data and would like to import it. Please guide.

Thanks loads.

Rishi, on Catia V5 R18 WinXP 32/ on Catia V5 R19 Win Vista 32

Samarinder Singh

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hi Milton,
The macro is working fine for me as long I use text file. However, it is giving me some errors when I try to export the points in Excel file format.
R19sp4 win XP pro 32bit MSO2007
few questions:
Do I have to have excel open at time of running the macro?
Do I have to have a blank file saved from Excel prior to run this macro?

We're using MSO 2007 now by the way, so you may also have to change the References Excel xx.0 entry.

Do I have make that change inside the macro in order to run with MSO 2007?
Thanks

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

@HMandyam: The most recent macro should be able to import as many points as your workstation can handle.  It will run a very long time I think, but it theoretically should complete.

@Samarinder: The Export dialog specifies 'An open Excel sheet'.  You need to have Excel running and you will select a range in the Excel sheet.  You are able to select multiple non-adjacent ranges, even on separate pages.  Also, each person using the macros may have to change their reference library setting.

Roger Leach

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

We are running XP Pro x64 with x64 CATIA R18SP7 and the macro successfully puts values into Excel, but all these values are ZERO (0). The text file output is also ZEROs (0).

Also, if we choose the axis option we we get the attached error.

Are there any settings that are different for x64?

Thanks,

Roger

 

 



James Woodard

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

I realize this tool already does a lot and looks great but I run into something else all the time and was wondering about getting it automated.  Many projects that I am involved with requires the coordinates of a large number of points within a part file to be updated with values from an excel spreadsheet.  I was wondering if something like that would be hard to implement into this tool?  Thanks.

Samuel Lindholm

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Posted By LUENYAR on 23 Apr 2008 02:58 PM
Sorry, I wasn't very clear I think. These MUST be imported into a VBA project. To my knowledge this limits you to Windows-based I'm pretty sure. Anyway here are the steps that should hopefully lead to everyone's success.

1. Within CATIA, click Tools -> Macros->Macros.
2. Click the 'Macro libraries' button.
3. Under 'Library type:' choose 'VBA Projects', then click the 'Create new library' button. Enter the path and file name you want here.
4. Close the 'Macro Libraries' window.
5. Within CATIA, click Tools->Macros->VB Editor.
6. Select the new Library from the tree on the left side, then click File->Import File.
7. Set 'Files of type' to All *.*, and browse and select to where you saved the .txt files from me. Pick one and repeat 7 for the other.
8. Lastly, before exiting VB Editor, click Tools->References. Find 'Microsoft Excel 11.0 Object library' and check it. If it is Excel 9 or 10 or 12 or something, it should still work fine. 11.0 is just what is with Office 2003.
9. Save the VB Project and close the Editor.
10. Now in Tools->Macros you can run these modules you just imported. If you have CATScript and Catvbs macros that you need as well, simply change the 'Current macro library or document' to the Macro folder you had defined before.

Look back over my original post for some usage ideas. And let me know if you have other questions.

 

Shailesh Sathe

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hi LUENYAR,

 

Can you please send me this macro. my id is [login to unmask email].

 

I am new to this forum and i need this maco to import sthje points in CATIA V5.

 

I am hoping to get help from you.

 

Shailesh

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
I am just beginning to learn VB and CATIA scripting (my background is on the C side of programming). I am grateful for your script, as it does almost everything I need to do at the moment. I've already learned a lot from it.

What I would like to do is to take a list of points that are labeled into sets to create polylines from these sets of points.

For example, this is part of my input:
240,40,750,0
240,20,750,0
240,20,140,0
240,40,140,0
240,40,750,0
241,40,-750,0
241,60,-750,0
241,60,-140,0
241,40,-140,0
241,40,-750,0

This gives me 5 points labeled "240" and 5 labeled "241". What function calls would I use, which I can add to this macro, to create polylines from this type of input? I would greatly appreciate any direction as I try to make sense of the CATIA API. By the way: is there a good CATIA API reference out there?

Best,
Matthew

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Shailesh, the link to the file is on the previous page. Here it is:

http://www.coe.org/Portals/0/NTForums_Attach/15672088363.zip

Best,
Matthew

Shailesh Sathe

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi mathew,

Thanks a lot for that.

One more request i have. Could you send me the .txt files you wrote about in the post?

I am getting error when i click import points from excel

The error is "cant find project library". I am very poor in Visual basic so i m not getting what it is.

Thanks for the help in advance.

Shailesh

Brian Phelps

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

I don't see where this vba is available.  Where can I find it?

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

We don't really have any public website, but I had this posted where it can at least be downloaded  Hopefully this makes it easier to find the latest Macro file.

Download PointsMacros.zip

Roger Leach

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Does this one run on XP x64 with 64-Bit CATIA?

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Unless they've changed the 64-bit CATIA code or API or something, then no.  As far as I can tell, no one has had luck getting point coordinates from the 64-bit CATIA.  It works for me on Vista 64 running 32-bit CATIA.

Mike Berry

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
LUENYAR,

Have you tried using the measurable object to get the point coords instead of the GetCoordinates method on the point? Measurable method works on 64bit CATIA...

Example...
Dim varCoords(2) As Variant
Set objSPAWorkbench = objPart.Parent.GetWorkbench("SPAWorkbench")
Set objPtRef = objPart.CreateReferenceFromObject(objPt)
Set objMeasurable = objSPAWorkbench.GetMeasurable(objPtRef)
objMeasurable.GetPoint varCoords
MsgBox Join(varCoords, ", ")

-Mike

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
I haven't explored this, no. I may explore this when I can. Because GetMeasurable uses the SPAWorkbench reference, does it require an SPA license?

Mike Berry

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Definitely does not require SPA license and to best of my knowledge there are no other license requirements either. Definitely give it a try in your next release...

Also, I just downloaded your vba project - nice work!

-Mike

Daniel Cernada

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Luenyar,
I'm looking for a macro to export catia points (pasted as result) to excel, I think I'm in the right post,
but, How can I download your macro??,
It has a link to another website with a password, do you know what the password is?

Thank you

Daniel

Knight Zwy

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
why can't i download the zip, it needs me to log in.when i used the COE ID, it did work.
need your help.

Jack Rowe

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

I can run this program and it works but is there to run this from within a product and run it on all of the parts.  Note I am a newbie.

 

 

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
There is no option to run as you have asked.

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Hi,I was just trying to make it work but in some step I am probably wrong...When I complete the 6th step I have a messsage 'this file cannot be loaded'...I had extracted it on my desktop as a catvba file and not as a text...I am using Windows Vista as operating system on my Laptop and I can't change it into text,I only opened it with the notepad and the result is the same...Can I have some help here???

 

Antonis

Andrew Armstrong

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Antonis,

Open the VB Editor (ALT+F11)
Choose File->Macro Libraries...

Change the Library type: to VBA projects
Click Add existing library...
Choose the file from your desktop, and it should appear in your Current libraries
Close the Macro libraries box, and the project should now be in the tree in the VB editor
To run, click ALT+F8 in CATIA, and run the proper module

Hope this helps!

Andrew Armstrong

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

Andrew thanks a lot,I had already done it before your post,but thanks anyway m8!

 

The other thing is that I can't export the points...This sub-program shows a message 'set the geometry of points' or something like this....WHAT THE HECK does that mean?I set the drafting geometry at the left of the screen but sends me back 'No points inlcuded' or something like this..Can anyone write doen the process and what do I have to select?????

 

Antonis G. Stamopoulos

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Thanks very much Milton

I've never done anything like this before, but eventually got it to run once I followed your instructions exactly, rather than thinking for myself.

Thanks

Geoff

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
What am I doing wrong?????I cannot output the points...The macro wants geometric set of points...I chose it at the upper left of the screen in CATIA and the result is a message 'no points found'....What do I have to do????

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

I finally got the time to make the Export functions work with the 64-bit CATIA code. I only ran a couple of tests on a 64-bit machine, but it seemed to work great. Thank yous to Mike Berry for the Measurable suggestion, that is what I employed to fix it. Enjoy!

Download PointsMacros.zip

Maryam Khelghati

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Milton,
I want to import some points from excel to catia.I read your comments,but I can not download PointsMacros.zip file.the error is that I dont have permission! would you please send it to me via E-mail?? my E-mail adsress is: [login to unmask email]
Thanks a lot
Maryam

Luke Huckin

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Milton,

I would like to use your macro to import a large amount of points for a reverse engineering work package I'm performing.

Could you email me the marcro or put it into your dropbox again.

Many thanks

Luke

[login to unmask email]

Lim Kenta

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi Luenyar

I am download your catvba. add in in a macro and try to click run. it mentioned "run time error. tye mismatch.

may i know why?

furthermore,i follow all your instruction
"7. Set 'Files of type' to All *.*, and browse and select to where you saved the .txt files from me. Pick one and repeat 7 for the other."

what is the txt file?i cant search.thanks

looking forward to your reply

Xia Salud

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

I got it ! Many thanks for LUENYAR and Luke, and i will try it again !

Andrew Moro

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hey Milton,

Whenever I try to run the macro I get the following errors:

“Macros (line 0) raised an unexpected error 429 (ActiveX component can’t create object)”
“Macros (line 0) raised an unexpected error 91 (object variable or with block variable not set)”

Do you have any insight as to how to fix these problems?

I am running this on CATIA V5R18 with Windows XP SP3.

Thank you so much for any help you can provide.

~Andrew

Little Cthulhu

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
amoro04, hi.

Try following script - http://www.catiav5forum.de/wbb3/wbb/index.php?page=Thread&threadID=4273 (be sure to get it's latest version)

Andrew Moro

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Perfect! Thanks!

COE Administrator

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hello

Great macro! I was just wondering is it possible for me to export points from one face at a time instead of exporting the full range of points from the part? I am really stuck as to how I would go about doing this

Milton Hartung

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
If you have one or more points selected BEFORE you run the macro, it should use those instead of asking for a selection. Remember Alt+F8 is the Macros shortcut if you have to close the macro between selections. Or maybe try to create the points in different Geo Sets so you can select those individually.

Ni Wayne

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
LUENYAR,i have no idea why i cannot download your attachment Download PointsMacros.zip, so would you email it to me.thank you. email:   [login to unmask email]

Joe Hayden

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hello Milton,

I'm trying to import point coordinates for airfoil sections into CATIA and this script looks like it's the answer to all my problems, well maybe not all but . . . I believe I've followed your instructions to the letter but still can't get the macro to run. Obviously I'm missing something important!

At the very beginning of this post you say to rename the .txt file to .bas but when I unzip the folder after downloading the only thing in there is a .catvb file, so I'm not sure which file I need to rename.

When I try to run ImportPoints from the Macro window nothing happens. If I try to run one of the Modules that gets created after importing a .txt file with the point coordinates I get an error box: "The script entry point could not be found. Define a "CATMain" procedure which will be the entry point of the script."

I am running CATIA V5R18 on Windows XP64 SP2. Thanks for your help!

-Joe

Little Cthulhu

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)
Hi.

Take a look 5 posts above:

"Try following script - http://www.catiav5forum.de/wbb3/wbb/index.php?page=Thread&threadID=4273 (be sure to get it's latest version)"

bharath17 bharath

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

hi

i dont know much about vba but with help of my friends i was able to extract points from catia to excel,

and also from excel to catia.

i have isolated series of points i want to make them coordinates.

i want to make the points as coordinates without creating new points as they are in link with the curves.

can u please suggest any solution for this.

thanks for ur previous msgs which help me alot

Edited By:
bharath17 bharath[maxindra] @ Sep 04, 2012 - 10:57 PM (Asia/Calcutta)

Little Cthulhu

RE: CATIA points and Excel: there and back again
(in response to bharath17 bharath)


The only solution I found is with the help of WinAPI.

Script below should be run as catvba project (not as CATScript).

 

'==============================================================================
'
'               WINAPI DECLARATIONS
'
'==============================================================================
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" ( _
        ByVal hWndParent As Long, _
        ByVal hWndChildAfter As Long, _
        ByVal lpszClass As Any, _
        ByVal lpszWindow As Any) As Long
        
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" ( _
        ByVal hWnd As Long, _
        ByVal iIndex As Long) As Long
        
Private Declare Function SetActiveWindow Lib "User32" ( _
        ByVal hWnd As Long) As Long
        
Private Declare Function IsWindowEnabled Lib "User32" ( _
        ByVal hWnd As Long) As Integer
        
Private Declare Function IsWindowVisible Lib "User32" ( _
        ByVal hWnd As Long) As Integer
        
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" ( _
        ByVal hWnd As Long, _
        ByVal Msg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
        
Private Declare Function PostMessage Lib "User32" Alias "PostMessageA" ( _
        ByVal hWnd As Long, _
        ByVal Msg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
        
Private Declare Function GetMenu Lib "User32" ( _
        ByVal hWnd As Long) As Long
        
Private Declare Function GetSubMenu Lib "User32" ( _
        ByVal hMenu As Long, _
        ByVal nPos As Long) As Long
        
Private Declare Function GetMenuItemCount Lib "User32" ( _
        ByVal hMenu As Long) As Long
                
Private Declare Function GetMenuItemID Lib "User32" ( _
        ByVal hMenu As Long, _
        ByVal nPos As Long) As Integer
'==============================================================================
'
'               WINAPI CONSTANTS
'
'==============================================================================
Private Const WM_COMMAND = &H111
Private Const WM_SYNCPAINT = &H83
Private Const GWL_ID = -12
Private Const BM_CLICK = &HF5
Private Const BN_CLICKED = &H0
Private Const CBN_SELENDOK = &H9
Private Const CB_SETCURSEL = &H14E
Private Const CB_SHOWDROPDOWN = &H14F
Private Const CB_GETDROPPEDSTATE = &H157
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private Const MK_LBUTTON = 1
'==============================================================================
'
'               MACRO ENTRY POINT
'
'==============================================================================
Sub CATMain()
    '-------------------------
    ' FIND ALL EXPLICIT POINTS
    '-------------------------
    ' get Part root
    Dim prtRoot As Part
    Set prtRoot = CATIA.ActiveDocument.Part
    ' get Parameters collection
    Dim oParameters As Parameters
    Set oParameters = prtRoot.Parameters
    
    ' search for explicit points
    Dim iParameter As Integer
    Dim pntExplicitPoint As HybridShapePointExplicit
    Dim colExplicitPoints As New Collection
    
    For iParameter = 1 To oParameters.Count
    
        ' try to access parameter on HybridShapePointExplicit interface
        Set pntExplicitPoint = Nothing
        On Error Resume Next
            Set pntExplicitPoint = oParameters.Item(iParameter)
            
        If ((Err.Number = 0) And Not (pntExplicitPoint Is Nothing)) Then
            ' add point to collection
            colExplicitPoints.Add pntExplicitPoint
            
        Else
            ' error occured
            Err.Clear
            
        End If
    Next
    
    '--------------------------------------------
    ' CAST ALL FOUND EXPLICIT POINTS TO LIVE ONES
    '--------------------------------------------
    ' check that Part Design or Generative Shape Design workbenches are loaded
    Dim sWorkbench As String
    sWorkbench = CATIA.GetWorkbenchId()
    
    If Not ((sWorkbench = "PrtCfg") Or (sWorkbench = "CATShapeDesignWorkbench")) Then
        ' start Part Design if necessary
        CATIA.StartWorkbench "PrtCfg"
    End If
    
    Dim sResult As String
    Dim pntLivePoint As HybridShapePointCoord
    Dim iPoint As Integer
    
    For iPoint = 1 To colExplicitPoints.Count
    
        ' get another explicit point from collection
        Set pntExplicitPoint = colExplicitPoints.Item(iPoint)
        
        ' try to cast point to live
        sResult = ""
        Set pntLivePoint = CastExplicitPointToCoord(pntExplicitPoint, sResult)
        
        If (sResult <> "OK") Then
            MsgBox sResult, vbCritical, "Error casting " & pntExplicitPoint.Name
            Exit Sub
        End If
    Next
    
    '----------------------------
    ' DISPLAY FINISH NOTIFICATION
    '----------------------------
    MsgBox "Point casting done without error. " & vbCr & _
            "Total number of points casted: " & CStr(colExplicitPoints.Count), _
            vbInformation, "Finished"
    
End Sub
'==============================================================================
'   Method:       CastExplicitPointToCoord
'------------------------------------------------------------------------------
'   Using WinAPI opens explicit point Definition dialog window and change point
'   type to "Coordinates".
'
'----------
'   Input:
'----------
'       ByRef pntExplicitPoint As HybridShapePointExplicit
'               Explicit point to be casted to "point by coordinates" feature.
'
'       ByRef sResult As String (OPTIONAL, DEFAULT="")
'               Variable to store result of method execution. Stores "OK" if
'               no errors occurs, otherwise stores error description.
'
'----------
'   Output:
'----------
'       oResult As HybridShapePointCoord
'               Casted point accessed on HybridShapePointCoord interface
'
'==============================================================================
Private Function CastExplicitPointToCoord( _
                ByRef pntExplicitPoint As HybridShapePointExplicit, _
                Optional ByRef sResult As String = "") As HybridShapePointCoord
    ' set default value
    Set CastExplicitPointToCoord = Nothing
    ' quickly check inputs
    If (pntExplicitPoint Is Nothing) Then
        sResult = "Argument missing. Explicit point was not specified"
        Exit Function
    End If
    
    '-----------------------------
    ' RETRIEVE CATIA WINDOW HANDLE
    '-----------------------------
    Dim hwndCATIA As Long
    hwndCATIA = GetCATIAWindowHandle()
    
    If (hwndCATIA = 0) Then
        sResult = "Can't retrieve CATIA window handle"
        Exit Function
    End If
    
    
    '--------------------------
    ' SELECT POINT TO BE CASTED
    '--------------------------
    ' retrieve Selection object
    Dim oSelection As Selection
    Set oSelection = CATIA.ActiveDocument.Selection
    
    oSelection.Clear
    oSelection.Add pntExplicitPoint
    
    ' refresh CATIA
    CATIA.RefreshDisplay = True
    
    '--------------------------------------------------------
    ' GET CATIA MENUS - DOESN'T WORK WITH IN-PROCESS MACRO!!!
    '--------------------------------------------------------
    ' when point gets selected menu refreshes
    ' we need to stay in a loop to wait for end of refresh
    Dim hmnMainMenu As Long
    Dim iNbItems As Long
    Dim hmnEditMenu As Long
    Dim hmnObject As Long
    Dim idDefinition As Integer
    
    idDefinition = 0
    Do While (idDefinition <= 0)
        ' main menu
        hmnMainMenu = GetMenu(hwndCATIA)
        iNbItems = GetMenuItemCount(hmnMainMenu)
        ' Edit submenu
        hmnEditMenu = GetSubMenu(hmnMainMenu, iNbItems - 6 - 3)
        iNbItems = GetMenuItemCount(hmnEditMenu)
    
        ' Object submenu
        hmnObject = GetSubMenu(hmnEditMenu, iNbItems - 1)
        
        ' command ID
        idDefinition = GetMenuItemID(hmnObject, 0)
        
    Loop
        
    '------------------------
    ' CALL DEFINITION COMMAND
    '------------------------
    ' call command retrieved from menu
    Dim HRESULT As Integer
    HRESULT = SendMessage(hwndCATIA, WM_COMMAND, idDefinition, 0)
    
    If (HRESULT = 0) Then
        sResult = "Error calling Definition command (Edit->Object->Definition)"
        Exit Function
    End If
    
    '-------------------------------
    ' WORKING WITH DEFINITION WINDOW
    '-------------------------------
    ' waiting for it to appear...
    Dim hwndDefinition As Long
    hwndDefinition = 0
    
    Do While (hwndDefinition = 0)
        CATIA.RefreshDisplay = True
        hwndDefinition = FindWindow(vbNullString, "Point Definition")
    Loop
    
    ' ... and to become enabled
    Dim iIsEnabled As Integer
    iIsEnabled = 0
    
    Do While (iIsEnabled = 0)
        iIsEnabled = IsWindowEnabled(hwndDefinition)
    Loop
    
    ' retrieving handle to "OK" button
    Dim hwndButtonOK As Long
    hwndButtonOK = FindWindowEx(hwndDefinition, 0, "Button", "OK")
    
    ' finding frame1
    Dim hwndFrame1 As Long
    hwndFrame1 = FindWindowEx(hwndDefinition, 0, vbNullString, "frame1")
    
    ' finding combobox
    Dim hwndCombobox As Long
    hwndCombobox = FindWindowEx(hwndFrame1, 0, "ComboBox", vbNullString)
    
    ' dropping down combobox
    HRESULT = SendMessage(hwndCombobox, CB_SHOWDROPDOWN, 1, 0)
    
    ' waiting for combobox to appear
    HRESULT = 0
    Do While (HRESULT = 0)
        HRESULT = SendMessage(hwndCombobox, CB_GETDROPPEDSTATE, 0, 0)
    Loop
    
    ' selecting first element ("Coordinates")
    HRESULT = SendMessage(hwndCombobox, CB_SETCURSEL, 0, 0)
    ' sending notification that choice has been made
    Dim idComboBox As Long
    idComboBox = GetWindowLong(hwndCombobox, GWL_ID)
    
    Dim LVALUE As Long
    LVALUE = CBN_SELENDOK
    LVALUE = LVALUE * 16 * 16 * 16 * 16 + idComboBox
    HRESULT = SendMessage(hwndDefinition, WM_COMMAND, LVALUE, hwndCombobox)
    ' hiding dropped menu
    'HRESULT = SendMessage(hwndCombobox, CB_SHOWDROPDOWN, 0, 0)
    
    '--------------------------------
    ' CLOSING POINT DEFINITION WINDOW
    '--------------------------------
    ' waiting for button to become  enabled
    HRESULT = 0
    Do While (HRESULT = 0)
        CATIA.RefreshDisplay = True
        HRESULT = IsWindowEnabled(hwndButtonOK)
    Loop
    
    ' clicking on button
    Call SetActiveWindow(hwndButtonOK)
    HRESULT = SendMessage(hwndButtonOK, BM_CLICK, 0, 0)
    HRESULT = SendMessage(hwndDefinition, BN_CLICKED, 0, 0)
    
    ' waiting for window to disappear
    HRESULT = 1
    Do While (HRESULT = 1)
        CATIA.RefreshDisplay = True
        HRESULT = IsWindowVisible(hwndDefinition)
    Loop
    sResult = "OK"
End Function
'==============================================================================
'   Method:       GetCATIAWindowHandle
'------------------------------------------------------------------------------
'   Retrieves handle to CATIA window.
'
'----------
'   Output:
'----------
'       Result As Long
'               Handle to CATIA window.
'
'==============================================================================
Private Function GetCATIAWindowHandle() As Long
    ' compose a proper text for the caption of CATIA window
    Dim sCATIALabel As String
    sCATIALabel = CATIA.Caption
    ' check if there is any document opened in CATIA
    Dim docActive As Object
    On Error Resume Next
        Set docActive = CATIA.ActiveDocument
    If (Err.Number <> 0) Then
        Err.Clear
        Set docActive = Nothing
    End If
    If Not (docActive Is Nothing) Then
        If (CATIA.ActiveWindow.WindowState = INFITF.CatWindowState.catWindowStateMaximized) Then
            sCATIALabel = sCATIALabel & " - [" & CATIA.ActiveWindow.Caption & "]"
        End If
    End If
    ' find window by it's caption
    Dim hwndCATIA As Long
    hwndCATIA = FindWindow(vbNullString, sCATIALabel)
        
    ' return found handle
    GetCATIAWindowHandle = hwndCATIA
End Function

bharath17 bharath

RE: CATIA points and Excel: there and back again
(in response to Little Cthulhu)

Thanks a lot, its working and this was very helpful for me.

Edited By:
bharath17 bharath[maxindra] @ Jan 27, 2012 - 02:04 PM (Asia/Calcutta)

Richard Campbell

RE: CATIA points and Excel: there and back again
(in response to Milton Hartung)

I am aunable to get the macros working in V5 R20, any help is greatly appreciated.

 

When I run it it returns Compile error:  Can't find project or library. After you hit enter or select OK it highlights "Dim catDocument As PartDocument" in blue and "Public Sub ExportToFile(ByVal dbScale As Double, ByVal strFilename As String, ByVal tfUseNames As Boolean, ByVal tfUseAxis As Boolean, ByVal intPrecision As Integer, ByVal strSeparator As String)" in yellow

I'm not sure where to go from here...

Little Cthulhu

RE: CATIA points and Excel: there and back again
(in response to Richard Campbell)
Hi.
Are you trying to run it from excel? If so, in VBA editor go to Tools-References menu and check all CATIA V5 libraries.

Richard Chambers

RE: CATIA points and Excel: there and back again
(in response to Little Cthulhu)

Sorry for opening an old thread, but does anyone have an updated Macro for R2013 to export points from a geometrical set and place them in Excel?

 

Thank you,

Richard

Richard Chambers

RE: CATIA points and Excel: there and back again
(in response to Richard Chambers)

This is what I have so far - but I get the "Type mismatch: 'point.GetCoordinates' error on line: 37

 

Sub CATMain()

CATIA.ActiveDocument.Selection.Search
"CATGmoSearch.Point,all"
StartEXCEL

ExportPoint

'objGEXCELSh.Application.ActiveWorkbook.SaveAs (ExcelFolder
& Left(CATIA.ActiveDocument.Name,Len(CATIA.ActiveDocument.Name)-8) &
".xls")

'objGEXCELSh.Application.ActiveWorkbook.Close

End Sub

'******************************************************************************

Sub StartEXCEL()

'******************************************************************************

Err.Clear

On Error Resume Next

Set objGEXCELapp = GetObject
(,"EXCEL.Application")

If Err.Number <> 0 Then

Err.Clear

Set objGEXCELapp = CreateObject
("EXCEL.Application")

End If

objGEXCELapp.Application.Visible = TRUE

Set objGEXCELwkBks = objGEXCELapp.Application.WorkBooks

Set objGEXCELwkBk = objGEXCELwkBks.Add

Set objGEXCELwkShs = objGEXCELwkBk.Worksheets(1)

Set objGEXCELSh = objGEXCELwkBk.Sheets (1)

objGEXCELSh.Cells (1,"A") = "Name"

objGEXCELSh.Cells (1,"B") = "X"

objGEXCELSh.Cells (1,"C") = "Y"

objGEXCELSh.Cells (1,"D") = "Z"

End Sub

 

'******************************************************************************

Sub ExportPoint()

'******************************************************************************

For i = 1 To CATIA.ActiveDocument.Selection.Count

Set selection = CATIA.ActiveDocument.Selection

Set element = selection.Item(i)

Set point = element.value

'Write PointData to Excel Sheet

point.GetCoordinates(coords)

objGEXCELSh.Cells (i+1,"A") = point.name

objGEXCELSh.Cells (i+1,"B") = coords(0)

objGEXCELSh.Cells (i+1,"C") = coords(1)

objGEXCELSh.Cells (i+1,"D") = coords(2)

Next

End Sub