Jump to content

Recommended Posts

Posted

I've been working with some code I've found on the Internet and have successfully managed to link AutoCAD to Excel.

 

I have a couple of questions though. Firstly, are the functions that are loaded from Excel.exe using code such as...

 

(vlax-import-type-library

:tlb-filename tbl ;Table

:methods-prefix "xlm-" ;methods

:properties-prefix "xlp-" ;properties

:constants-prefix "xlc-" ;constants

)

 

...documented anywhere? Apropos isn't much help. Excel doesn't seem to have anything.

 

Secondly, I can clear a range of cells on a cell by cell basis (using xlp-put-Value2) but this takes a while. Is there a function to clear a range, say A4:C500, in one go?

 

Cheers, Chris

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    10

  • Commandobill

    7

  • CrustyFur

    6

Posted

The methods aren't documented too well at all.

 

There is some info found in here:

http://midpointcad.com/au/docs/lakose_The_Visual_LISP_Developers_Bible.pdf

 

If you are still stuck, you may get a better response at theSwamp.org

 

As an aside, Please don't double post, it makes the Mods job even harder and just confuses things.

 

Lee

Posted

On another note. From my experience the Excel functions are not necessary to link autocad and excel.

Posted

Good point Bill,

 

See this for an example:

http://www.cadtutor.net/forum/showthread.php?t=37127

Posted
(setq    xlApp (vlax-get-or-create-object "Excel.Application")
         xlCells       (vlax-get-property
                          (vlax-get-property
                           (vlax-get-property
                            (vla-open
                             (vlax-get-property xlApp "Workbooks")
                            "c:\\book1.xls")
                           "Sheets")
                          "Item" 1)
                         "Range" "A1:A4"))
(vlax-map-collection xlcells 'vla-clear)

clears all contents. obviously edit the name and range

Posted
Good point Bill,

 

See this for an example:

http://www.cadtutor.net/forum/showthread.php?t=37127

 

Hey! where was my special thanks? :cry::P

Posted

Lee, that's a very useful document, thanks. I've only skipped through it at the moment as I'm on holiday (but still thinking work...!)

Posted
(setq    xlApp (vlax-get-or-create-object "Excel.Application")
         xlCells       (vlax-get-property
                          (vlax-get-property
                           (vlax-get-property
                            (vla-open
                             (vlax-get-property xlApp "Workbooks")
                            "c:\\book1.xls")
                           "Sheets")
                          "Item" 1)
                         "Range" "A1:A4"))
(vlax-map-collection xlcells 'vla-clear)

clears all contents. obviously edit the name and range

 

Excellent! That's going to help me a lot. Thanks.

Posted
Lee, that's a very useful document, thanks. I've only skipped through it at the moment as I'm on holiday (but still thinking work...!)

 

Yeah, its pretty good - but I think it sometimes just skirts around topics instead of delving too far into them. But a good read all the same.

Posted
(setq    xlApp (vlax-get-or-create-object "Excel.Application")
         xlCells       (vlax-get-property
                          (vlax-get-property
                           (vlax-get-property
                            (vla-open
                             (vlax-get-property xlApp "Workbooks")
                            "c:\\book1.xls")
                           "Sheets")
                          "Item" 1)
                         "Range" "A1:A4"))
(vlax-map-collection xlcells 'vla-clear)

clears all contents. obviously edit the name and range

 

Ah, another question for you if you don't mind... whilst I can make sense of the code above, the bit I'm missing is where you learnt it from in the first place. Do you know if the processes of getting worksheets, cell and ranges documented anywhere? I'm sure there's a whole load of other stuff that would be of use to me.

 

The Visual LISP Developers Bible that Lee recommended does actually say that 'this is not very clearly documented...' I'd worked that much out!

 

Regards, Chris

Posted

I suppose a vlax-dump of each object helps - but it still leads to trial and error.

 

I learnt the methods from Bill, and also Terry Miller's "GetExcel" program here, but I would be interested to see if the methods/hierarchy were documented anywhere.

 

Lee

Posted

Vla takes all of it's hierarchy from vba. If you open Excel and go into it's Visual Basic Editor Help it's all layed out for you right there just like in the Visual Lisp Help file

Posted
Vla takes all of it's hierarchy from vba. If you open Excel and go into it's Visual Basic Editor Help it's all layed out for you right there just like in the Visual Lisp Help file

 

 

Nice one Bill, so it is :)

Posted
Vla takes all of it's hierarchy from vba. If you open Excel and go into it's Visual Basic Editor Help it's all layed out for you right there just like in the Visual Lisp Help file

 

I'd been down that route before and searched for 'put-value' but as no results came up, thought I may be in the wrong place. I will dig a little deeper and also get one of our VBA programmers to have a look.

 

Thanks again, Chris

Posted

To put a value in a cell, you will need to get the Cells object, then use something like:

 

(vlax-put-property xlCells "Item" row col "test_string")

 

Where row and col are integers, and xlCells is the cells object.

Posted
I'd been down that route before and searched for 'put-value' but as no results came up, thought I may be in the wrong place. I will dig a little deeper and also get one of our VBA programmers to have a look.

 

Thanks again, Chris

 

Thats because 'put-value' isn't anything. Value is a property that belongs to a range object. With properties you can vla-get or vla-put.Thus vla-put-value. If you were to look up 'Value' you would have found that information. 8) I wouldnt be surprized if Lee could point you to a tutorial for the difference between "Collections, Objects, Properties, Methods, Events, etc.." Once you have that down it's a cake-walk

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