Jump to content

Recommended Posts

Posted

Hi,

 

I am have a database containing object information. I am able to write out a script from my database that inserts blocks into Autocad C3D. Here is an example of the script file:

osmode
0
-layer
Set
"2020_DESIGN"



ATTREQ 1
ATTDIA 0
-insert
"DESIGN"
607476.547,7574318.945,0 1 1 0
GAS
GR04L001
10354

Is there a way that I can also insert Object Data (into a data table) using this script when creating the block? 

 

I have attached an image showing the structure of the data table that I would like to populate.

 

Thanks in advance

 

Lee

Capture.PNG

Posted

If your doing lots of insert look at a lisp

 

Must it be Object data ? Why not invisible attributes much easier.

 

ade_odsetfield - AutoCAD Map 3D AutoLISP Documentation

 

Not sure about adding to block this is an example of get data. 

 

; simple object data example
; By Alan H July 2019

(defun c:odtest ( / ent ty odname dia material)
(setq ent (car (entsel "\n Select Polyline (or press Enter to Exit): ")))
(setq ty (cdr (assoc 0 (entget ent))))
	(if (and (eq "LWPOLYLINE" ty)
	  (/= (setq odname (ade_odgettables ent)) nil)
	   )
	 (progn
           (setq dia (ade_odgetfield ent odname "Diameter" 0))
           (setq mat (ade_odgetfield ent odname "Material" 0))
           (alert (strcat "Material: " mat " \nDiameter " (rtos dia 2 2) (chr 34) " Main"))
           )
         )
(princ)
)
(c:odtest)

 

Posted

Hi,

 

Thanks for your reply.

 

Unfortunately, yes it MUST be object data (a statutory requirement). While I have done plenty of VBA coding, I am unfamiliar with LISP - I find it quite hard to read. I will need to brush up on this. Not sure the boss will wait for me to learn LISP for a solution though 😉

Posted

Does anything here help. It is possible using a script but you can only pick table cells by entering coordinates so it would take a bit of study to create a working script.

Posted
1 hour ago, steven-g said:

Does anything here help. It is possible using a script but you can only pick table cells by entering coordinates so it would take a bit of study to create a working script.

 

This looks like its for a table, not Object Data?

Posted

Google object data VBA AUTOCAD. Should be examples.

 

Look at "Diameter " & "Material" replace with ASSET_TYPE & DATE_SURVEYED in example.

Posted (edited)

Hi BIGAL,

 

Quote

Google object data VBA AUTOCAD. Should be examples.

 

Look at "Diameter " & "Material" replace with ASSET_TYPE & DATE_SURVEYED in example.

 

I have Googled your suggestion, but I'm embarrassed to say I have no idea where to start with any of this. The best I can discern is that there is some kind of VBA add-on for AutoCad? 

 

At a loss....

Edited by lmorse
Posted

In Autocad you just type VBAMAN this will open VBA you can load or write new code. Much the same as in excel Macros. 

 

You simply VBALOAD a dvb then VBARUN the subroutine etc so in this example is a vba with lots of sub functions. The code snippet is lisp to run the PROJECTNO command.

 

(defun C:projectno ()
(vl-vbaload "P:/AutoDESK/VBA/Design Toolkit.dvb")
(vl-vbarun "add_project_number")
)

I found this example a couple of problems its based around 2004, version number will need to find current number Not tested 2020 is 23 ?

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