Jump to content

Coding issue exporting info automatically from Autocad 2016 to Excel 15


Recommended Posts

Posted (edited)

Hello all...

 

 

It's been a VERY long time since I was on this site, but I'm hoping that there a couple of hot shots still out there :-)

 

 

I've been tasked with writing a program that will extract attributes from AutoCAD and export them automatically into excel, and whilst I've got the program to work I can't get it to set the active worksheet prior to pushing the info into excel. The relevant fragment of code is as follows....

 

 

(vl-load-com)
 (setq tlbfile (findfile "C:\\Program Files\\Microsoft Office 15\\root\\office15\\Excel.exe"))
 (vlax-import-type-library :tlb-filename tlbfile :methods-prefix "msxl-" :properties-prefix "msxl-" :constants-prefix "msxl-")
 (setq xfile "c:\\attext_test.xls")
 (cond 
   ((setq fn (findfile xfile))
     (cond
       ((setq appsession (vlax-get-or-create-object "Excel.Application"))
         (vlax-invoke-method (vlax-get-property appsession 'workbooks) 'open fn)
         (vla-put-visible appsession 0)
       )
     )
   )
   (t (alert (strcat "nCannot locate source file: " xfile)))
 )
 (setq xlapp appsession)
 (msxl-Activate (vla-Item (msxl-Get-WorkSheets xlapp) "Instrumentation"))
 (setq rng (msxl-get-activesheet xlapp))

 

The second line to last should set the active page as "Instrumentation" in the excel file, but it doesn't.

 

 

Can anyone see what I'm doing wrong? I'll post the whole program for people to use as soon as I've got this sorted (plus the next program that pushes the info back from excel into the autocad attributes)

 

 

Best regards and thanks in advance

 

 

Spacepig62

Edited by SLW210
Added Code Tags
Posted

It's years (10+) since i did this stuff, and i hated type libraries with a passion, so avoided them. Perhaps you can adapt this code snippet for your need, I've replaced my xl_app with yours (xlapp) and inserted your sheet name into the first line

 

(setq activeSheet (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property xlapp "Sheets") "Item" "Instrumentation")))
(if (not (vl-catch-all-error-p activeSheet))					;if worksheet found
(vlax-invoke-method activeSheet "Activate")				;set it as activesheet
(setq activeSheet nil)
)

Posted

Hi dlanorh

 

Thanks very much for your help - I'll try it tomorrow at work and all being well I'll post the full program for everyone as soon as it's all tested - like you it's been years since I've done any major programming (I've been using Revit MEP since) - I wrote the original and posted that in 2006.....where have all the years gone?!?

 

Best regards

 

Spacepig62

Posted
It's years (10+) since i did this stuff, and i hated type libraries with a passion, so avoided them.

 

Just curious - why?

Are there any drawbacks by using type libraries or you just hate customly-named properties/methods/events?

Posted
Just curious - why?

Are there any drawbacks by using type libraries or you just hate customly-named properties/methods/events?

 

The code was being used across three versions of Excel, and each version had it's own type library IIRC. I found it a nightmare :ouch::ouch:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...