• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

creating a block on coordinates set in excel

  • Thread starter Thread starter anfaloni
  • Start date Start date

anfaloni

Guest
hello to everyone, and as always compliments for the many interesting ideas. .you never end up learning in this forum!! I wanted to have a problem that I've been trying to solve for a few days... In practice I have an excel file in which a numeric brand is inserted and x y z coordinates to me would serve as an atocad a macro that for each row of the excel table attributes to an attribute of an autocad block the number of the excel line and then moves me the block into the space with the coordinates shown in the excel line associated with the numeric brand.

said in a few words, if in a row I read: number mark n2, coordinated x, y, z, I would like in autocad that for each line of the excel table, in autocad I would like an appropriate autocad block containing the attribute "numeric mark" acquires the value of the excel cell relative to the numeric mark and that then it is moved into the space of the x,y,z coordinates on the row of the excel file. all this for all rows of table excel.

Is it possible for you? Do you have any opinions about this? Can you help me? thanks in advance for doseavailability
 
Sorry I've been seeing the forum lately,
the thing is feasible, but it takes a few extra points
example:
existing files with existing blocks to reposition/ update to change from excel file
existing files without blocks with blocks to be placed, and in case of modification of excel file recreate new file with new positioning
etc.
 
hello to everyone, and as always compliments for the many interesting ideas. .you never end up learning in this forum!! I wanted to have a problem that I've been trying to solve for a few days... In practice I have an excel file in which a numeric brand is inserted and x y z coordinates to me would serve as an atocad a macro that for each row of the excel table attributes to an attribute of an autocad block the number of the excel line and then moves me the block into the space with the coordinates shown in the excel line associated with the numeric brand.

said in a few words, if in a row I read: number mark n2, coordinated x, y, z, I would like in autocad that for each line of the excel table, in autocad I would like an appropriate autocad block containing the attribute "numeric mark" acquires the value of the excel cell relative to the numeric mark and that then it is moved into the space of the x,y,z coordinates on the row of the excel file. all this for all rows of table excel.

Is it possible for you? Do you have any opinions about this? Can you help me? thanks in advance for doseavailability
proof attachedView attachment Creazione blocco da Excel.rar
 
thank you very much for the availability! I will analyze it and test it! thanks again!
 
With this code, which goes well, you can insert a block from excel
option explicit

'a custom type that holds the scale factors of the block.
private type scalefactor
x as double
y as double
z as double
end type

sub insertblocks()

'--------------------------------------------------------------------------------------------------------------------------
'inserts blocks in autocad using data - insertion point, block name/full path, scale factors, rotation angle - from excel.
'note that the block name or the block path must already exists, otherwise nothing will be inserted.
'the code uses late binding, so no reference to external autocad (type) library is required.
'it goes without saying that autocad must be installed at your computer before running this code.

'written by: christos samaras
'date: 21/04/2014
'e-mail: [email protected]'yes: http://www.myengineeringworld.net
'--------------------------------------------------------------------------------------------------------------------------

'declaring the necessary variables.
dim acadapp as object
dim acaddoc as object
dim acadblock as object
dim lastrow as long
dim i as long
dim insertionpoint(0 to 2) as double
dim blockname as string
dim blockscale as scalefactor
dim rotationangle as double

'activate the coordinates sheet and find the last row.
with sheets("coordinates")
.activate
lastrow = .cells(.rows.count, "a").end(xlup).row
end with

'check if there are coordinates for at least one circle.
if lastrow < 2 then
msgbox "there are no coordinates for the insertion point!", vbcritical, "insertion point error"
exit sub
end if

'check if autocad application is open. if is not opened create a new instance and make it visible.
on error resume next
set acadapp = getobject(, "autocad.application")
if acadapp is nothing then
set acadapp = createobject("autocad.application")
acadapp.visible = true
end if

'check (again) if there is an autocad object.
if acadapp is nothing then
msgbox "sorry, it was impossible to start autocad!", vbcritical, "autocad error"
exit sub
end if
on error goto 0

'if there is no active drawing create a new one.
on error resume next
set acaddoc = acadapp.activedocument
if acaddoc is nothing then
set acaddoc = acadapp.documents.add
end if
on error goto 0

'check if the active space is paper space and change it to model space.
if acaddoc.activespace = 0 then '0 = acpaperspace in early binding
acaddoc.activespace = 1 '1 = acmodelspace in early binding
end if

on error resume next
'loop through all the rows and add the corresponding blocks in autocad.
with sheets("coordinates")
for i = 2 to lastrow
'set the block name.
blockname = .range("d" & i).value
'if the block name is not empty, insert the block.
if blockname <> vbnullstring then
'set the insertion point.
insertionpoint(0) = .range("a" & i).value
insertionpoint(1) = .range("b" & i).value
insertionpoint(2) = .range("c" & i).value
'initialize the optional parameters.
blockscale.x = 1
blockscale.y = 1
blockscale.z = 1
rotationangle = 0
'set the optional parameters (if there are values on the corresponding ranges).
if .range("e" & i).value <> vbnullstring then blockscale.x = .range("e" & i).value
if .range("f" & i).value <> vbnullstring then blockscale.y = .range("f" & i).value
if .range("g" & i).value <> vbnullstring then blockscale.z = .range("g" & i).value
if .range("h" & i).value <> vbnullstring then rotationangle = .range("h" & i).value
'add the block using the sheet data (insertion point, block name, scale factors and rotation angle).
'the 0.0174532925 is to convert degrees into radians.
set acadblock = acaddoc.modelspace.insertblock(insertionpoint, blockname, _
blockscale.x, blockscale.y, blockscale.z, rotationangle * 0.0174532925)
end if
next i
end with

'zoom in to the drawing area.
acadapp.zoomextents

'release the objects.
set acadblock = nothing
set acaddoc = nothing
set acadapp = nothing

'inform the user about the process.
msgbox "the blocks were successfully inserted in autocad!", vbinformation, "finished"

end sub
Now it would be useful that, someone better, make some changes
for example

currently, from excel, you choose the block, set the coordinates and stairs
assuming that the block in question has these attributes:
- tag1
- Term01
- Term02
- xref
How can you change the code to assign values?
 
to me does not ask for password

click tools-> macro-> management vba
opens the window "going vba"
click on the "load" button and go to the folder where you deposited the file "creation blocks from excel v2014_11_23.dvb"
click "open"
at that point you have the dvb in memory
click tools->macro->macro and select what ends with "...creation blocks from excel v2014_11_23.dvb!a1_main.updateblocchidaexcel"
 
With this code, which goes well, you can insert a block from excel


Now it would be useful that, someone better, make some changes
for example

currently, from excel, you choose the block, set the coordinates and stairs
assuming that the block in question has these attributes:
- tag1
- Term01
- Term02
- xref
How can you change the code to assign values?
I have updated my dvb but the attached load procedure does not work to me: after selecting the file from my pc, click the "download file" button but an error message "407 appears [IOErrorEvent type='ioError' bubbles = false cancelable=false eventPhase=2 text="Error #2038"]
 
I'm sorry, but I didn't understand your post well.
I have updated my dvb but the attached load procedure does not work
the attached prg is to be used under excel, so it is a xlsm, if you go here http://www.myengineeringworld.net/2014/07/insert-blocks-autocad-excel-vba.html
click the "download file" button
It's not dvb
then error
anyway apart everything
It seems to me that you are skillful on the cad side and everything about it
now we speak of the opposite side, in this case excel
you are used to using dvb x interacting with excel
here instead you want to use excel to interact with autocad
until now everything works well with the insertion of blocks
what is missing is: [blocco]aa1, sigla [TAG1] sps1, is an example
Hi.
 
I'm sorry, but I didn't understand your post well.

the attached prg is to be used under excel, so it is a xlsm, if you go here http://www.myengineeringworld.net/2014/07/insert-blocks-autocad-excel-vba.html It's not dvb
then error
anyway apart everything
It seems to me that you are skillful on the cad side and everything about it
now we speak of the opposite side, in this case excel
you are used to using dvb x interacting with excel
here instead you want to use excel to interact with autocad
until now everything works well with the insertion of blocks
what is missing is: [blocco]aa1, sigla [TAG1] sps1, is an example
Hi.
I said that I can't upload attachments to my posts on qs forum. and the attachment I wanted to upload is the update of the dvb origniariamente posted on 23/11/2014 with the changes to do what you asked a few days ago.

When I do, you will try dvb

as to the "transforming" in xslm is not a problem. between autocad and excel we work indifferently starting from one or other application, with few variations. but until I can load attachments, there is little to do
 
I said that I can't upload attachments to my posts on qs forum. and the attachment I wanted to upload is the update of the dvb origniariamente posted on 23/11/2014 with the changes to do what you asked a few days ago.

When I do, you will try dvb

as to the "transforming" in xslm is not a problem. between autocad and excel we work indifferently starting from one or other application, with few variations. but until I can load attachments, there is little to do
attach the file "creation blocks from excel.zip" containing:
- creation blocks from excel v2015_01_14.dvb; to be loaded from vba manager to be able to turn the macro "a1_main.updateblocchidaexcel";

- creating blocks from excel-2.xlsx; with the sheet "attributed" with the data in the appropriate format to be read by the macro of the dvb mentioned above. you can change/add rows and columns for your needs with the only limitation that
. the first line is dedicated to headers. of these are only significant ones from the 3rd column forward where the names of attributes are read
. the first three columns are dedicated to the coordinates of insertion of the block
. the columns from the 4th included in the forward are dedicated to attributes;

- update blocks from excel v2015_01_14.dwg; containing already examples blocks that match the names of xlsx file
 

Attachments

I opened both autocad and excel with your files
autocad gave me error in opening the dwg (impossible to load the project from memory) but opened it
the macro idem, was not performed, circumventing the problem by renameing the excel file with the name "attributed" now works
7 octagons appear with attributes assigned in excel.

Perhaps I am mistaken but the discussion is set on the fact that by excel I must be able to insert a certain chosen block and to it assign the attributes of the case
creating a block on coordinates set in excelto this I think I have answered

In addition,
said in a few words, if in a row I read: number mark n2, coordinated x, y, z,
I would like to autocad that for each line of table excel, in autocad I would like a
appropriate autocad block containing attribute
"numeric mark" acquires the value of the cell excel relative to the numeric brand and
then moved to the x,y,z coordinates space on the excel file line.
all this for all rows of table excel.
So I think of thisCattura_blocco.GIFwhere "numeric mark" can also be tag1, is an attribute

generally a block has a number (x) of attributes
then having the block, ev1.dwg
the insert coordinates, x, y, z
scales, x scale, y scale, z scale
rotation
knowing the attribute label to change
how you can change the value
 
I opened both autocad and excel with your files
autocad gave me error in opening the dwg (impossible to load the project from memory) but opened it
the macro idem, was not performed, circumventing the problem by renameing the excel file with the name "attributed" now works
7 octagons appear with attributes assigned in excel.

Perhaps I am mistaken but the discussion is set on the fact that by excel I must be able to insert a certain chosen block and to it assign the attributes of the case
creating a block on coordinates set in excelto this I think I have answered

In addition,


So I think of thisView attachment 39330where "numeric mark" can also be tag1, is an attribute

generally a block has a number (x) of attributes
then having the block, ev1.dwg
the insert coordinates, x, y, z
scales, x scale, y scale, z scale
rotation
knowing the attribute label to change
how you can change the value
the macro runs with any excel file name, the important thing is that it has a "attributed" sheet and that it is active. I suppose you ran the macro from autocad without first triggering the excel file that contains that folder. but having renamed it (and you could have called it also "xtz" you also made it active and, therefore, working.

the initial discussion was set on the request of anfaloni of 22/10/2014. on the 23/10 I posted the dvb that fulfills it. He said he'd let you know, but I haven't had any reconventions yet.
while the code you fished on the net and proposed on 12/01 does things other than those asked by anphaloni, while remaining in the very general theme (and very generic) "blocchi-autocad-excel"

then you posted a more articulated request. in the first line I realized that it was an extension of that of amphalons, having read "presupposing that the block in question has these attributes", and therefore I derived it from that already developed making it more general but always tied it to the condition that the blocks are already present in the drawing and that between them only those between whose attributes there are all those that the user requires in the excel sheet.

Now I understand better that your request is that you specify the blocks directly by name (and not indirectly to have certain attributes) and to insert them, among others, by varying the value of an attribute chosen by the user. and therefore assuming that the attribute chosen by the user is really contained in the block chosen by the user.
Is that so?
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top