Jump to content

send field expression to autocad from excel vba


Recommended Posts

Posted

I have an excel file in which, i have a data in cell A like "dia of circle" , and using a formula in cell B i calculate area of circle for e.g 22/7*(value of cell A /2)^2 , then in cell C , i use a concatenate command to combine values in cell A and cell B , then using vba i plot this text on autocad like "dia of 2 = 3.14" , but now i need to change its dia for which area should be calculate , i heard that autocad have insert field command by which it do calculation , but problems comes when i have to give objid , like i want to put formula in field 22/7*(text value /2 )^2 , here text value is the object that i have to select it manually , is there is way in vba  , that i added a text "2" , then add another text in which field expression is used containing previous text reference

Posted

Here is a lisp that returns object id you can rewrite into VBA it probably exists already just google, for the vl object part you can use the (entlast) as you are using excel to create circle.

 

; Thanks to Lee-mac

(defun LM:acdoc nil
   (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
   (LM:acdoc)
)

(defun LM:objectid ( obj )
   (eval
       (list 'defun 'LM:objectid '( obj )
           (if (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
               (if (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
                   (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
                  '(LM:ename->objectid (vlax-vla-object->ename obj))
               )
              '(itoa (vla-get-objectid obj))
           )
       )
   )
   (LM:objectid obj)
)

 

Posted
20 hours ago, khurram ali said:

i have a data in cell A like "dia of circle" , and using a formula in cell B i calculate area of circle for e.g 22/7*(value of cell A /2)^2

 

Why not use PI()? e.g.:

=PI()*(A1/2)^2

 

  • 1 month later...
Posted

if i want to insert field formula in auto cad, through excel , how can i do this , i don' want to use lisp , all my data is in excel form , if i want to draw a circle i simply type "c 0,0 d 10" then i copied it and paste to command line and circle is drawn , for multiple command i use excel vba to send it to auto cad , all i want is to write an expression for field that contain formula , then i copied and paste it to command line , to  achieve my desire results

Posted

i found some useful stuff on youtube

 

 

Posted
On 2/27/2020 at 9:57 AM, BIGAL said:

'(LM:ename->objectid (vlax-vla-object->ename obj))

 

You missed out the LM:ename->objectid function. Pretty sure it would yield an error "No function definition: LM:ename->objectid", though I haven't tried it on myself.

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