Telefisch Posted November 7, 2008 Share Posted November 7, 2008 Hello forum... I'm beginner in autoCAD and I'm writing a little Test-Program based on C#. Im trying to get the Blocks and their positions out of a drawing. Til now I'm able to get the names of the blocks but only one time. There are two identical blocks in the drawing and I'll have to get the positions of each, also the attribute-values. culd somebody help me solving this problem? If there are VBA-Codesnippets, this would perhaps help too. many thanks Telefisch Quote Link to comment Share on other sites More sharing options...
lpseifert Posted November 7, 2008 Share Posted November 7, 2008 Try Eattext (or Attext if 2004 doesn't have Eattext) Quote Link to comment Share on other sites More sharing options...
Telefisch Posted November 7, 2008 Author Share Posted November 7, 2008 thanks for the answer. is this an ACAD Command? I need something to red this info by code. Quote Link to comment Share on other sites More sharing options...
lpseifert Posted November 7, 2008 Share Posted November 7, 2008 It's an Autocad command. If you need code, someone will probably be along soon to help. or try here ; a good source for programming, you'll need to register, but it's free. Quote Link to comment Share on other sites More sharing options...
Telefisch Posted November 7, 2008 Author Share Posted November 7, 2008 Thanks... looks interresting. If someone has an idea, let me know. since then I'll search in theswamp. Telefisch Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 7, 2008 Share Posted November 7, 2008 Perhaps this: (defun c:blocext (/ fpath) (setvar "cmdecho" 0) (setq fpath (getstring t "\nSpecify Filepath to Save to: ")) (command "-eattext" "C" "Y" "Y" "" "Xls" fpath) (setvar "cmdecho" 1) (princ) ) ; end blocext This will write all block information to an Excel Doc, and save it in the specified location. Specify you location like this: "C:\XXX\XXX\filename" And the LISP will create an Excel doc called "filename", and save it to "C:\XXX\XXX" Or, if you are using the same location every time: (defun c:blocext2 (/ fname fpath) (setvar "cmdecho" 0) (setq fname (getstring t "\nSpecify Filename: ")) (setq fpath (strcat "[b][color=Red]C:\\Users\\[/color][/b]" fname)) ; <<---<< Change this line for a different Location (command "-eattext" "C" "Y" "Y" "" "Xls" fpath) (setvar "cmdecho" 1) (princ) ) ; end blocext2 Let me know if this helps at all Quote Link to comment Share on other sites More sharing options...
Telefisch Posted November 8, 2008 Author Share Posted November 8, 2008 first, many thanks to lee mac and lpseifert... I was searching for a way to solve this with an activex-control of Open Design Alliance. Because its similar in many points, I hoped that I can find a little help here. I'm still thinking this DWGdirectX-Control isn't very different to ACAD-Api so I think my way solving this problem could be helpfull to others... So, thats it in C#: try { foreach (IAcadEntity blk in oDoc.ModelSpace) //iterate thru all Entities in Modelspace { if (blk.ObjectName == "AcDbBlockReference") //If the Entity is a Block Reference, go on. { IAcadBlockReference blkRef = (IAcadBlockReference)blk; //Cast Entity to BlockReference if (blkRef.EffectiveName.Substring(0, 4).ToLower() == "pdms") //just filter the needed Blocks { //List Name of Block in Listview strItem[0] = "Name"; strItem[0] = blkRef.EffectiveName; item = new ListViewItem(strItem); lvw.Items.Add(item); //Get InsertionPoint and Cast it to double-array double[] dblPosition = (double[])blkRef.InsertionPoint; //insert the Position in Listview strItem[0] = "Position X"; strItem[1] = Convert.ToString(dblPosition[0]); item = new ListViewItem(strItem); lvw.Items.Add(item); strItem[0] = "Position Y"; strItem[1] = Convert.ToString(dblPosition[1]); item = new ListViewItem(strItem); lvw.Items.Add(item); strItem[0] = "Position Z"; strItem[1] = Convert.ToString(dblPosition[2]); item = new ListViewItem(strItem); lvw.Items.Add(item); ... HTH, Telefisch Quote Link to comment Share on other sites More sharing options...
wannabe Posted November 8, 2008 Share Posted November 8, 2008 What about accessing the drawing's database using the arx index? Quote Link to comment Share on other sites More sharing options...
Zeusovsky Posted January 5, 2009 Share Posted January 5, 2009 In VBA you could use this Code: Public Sub BlocksSearch () Dim Block as AcadBlock For Each Block in ThisDrawing.Blocks MsgBox "The Block Name is: " & Block.Name & " The Insertion Point is: " Block.InsertionPoint" Next Block Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 6, 2009 Share Posted January 6, 2009 The Vba and C are very similar using Zeusovsky above you would search for all blocks then make a list then sort the list by block name before outputting the result. rather than foreach Dim SS As AcadSelectionSet Dim Count, Cntr As Integer Dim FilterDXFCode(0) As Integer Dim FilterDXFVal(0) As Variant Dim basepnt, pt1, pt2, pt3 As Variant FilterDXFCode(0) = 0 FilterDXFVal(0) = "INSERT" Set SS = ThisDrawing.SelectionSets.Add("MyBLOCKS") SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal For Cntr = 0 To SS.Count - 1 BLOCK_NAME=SS.Item(Cntr).Name Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.