Skip to main content
Autodesk India Community logo
Login | Register
  • Home
  • Resources
  • Blog Roll
    • Autodesk Labs
    • Autodesk Videos
    • CAD Professor
    • Computer Graphics India
    • Inventor Certification
    • Inventor talks
    • Lynn Allen
    • Mastering CAD
    • Shaan Hurley
    • Small Guru
    • Subhendu 3D
    • What A Mesh
    • Mastering AutoCAD
  • Forums
    • Getting Started
    • AutoCAD General
    • AutoCAD Topic Specific
    • AutoCAD Customization
    • AutoCAD LT
    • Autodesk Inventor
    • Autodesk Revit
  • Social Media
    • Facebook
    • Twitter
  • Contact Us
    • Autodesk Communities
    • Community Contributors
  • Autodesk India
AutoCAD 2014

Learn more about AutoCAD 2014 and its features

Learn More
AutoCAD LT 2014

Learn more about AutoCAD LT 2014 and its features

Learn More
Autodesk Inventor 2014

Learn more about Autodesk Inventor 2014, new features 

Learn More
Autodesk Revit 2014

Learn more about Revit 2014

Learn More

AutoCAD Customization

I want to read data from a DWG excel file using C#.

AutoCAD Customization: .NET - Fri, 2013-05-10 11:19

I want to read data from a DWG excel file using C#. 

Categories: AutoCAD Customization, Autodesk Forums

DIMSTYLES : Creating, Modifying and Setting Current

AutoCAD Customization: .NET - Fri, 2013-05-10 10:50

OK.  This is not so much a cry for help as a post that might help someone else.

 

I was trying to find concise code that would let me create a dimension style (if it didn't exist), or modify a dimension style (if it did), that complied with our particular drafting standards.

 

I also wanted code that would enable me to set the dimstyle current.

 

Well, below is what I arrived at with the help of about 20 different blog and forum posts that gave me different components of the whole.  Google's wonderful until you're snowed with irrelevant results.

 

My code looks a bit inflexible because it's meant to be.  I don't want someone deciding that their 'standard' is better than the one they're supposed to use.  If you take this on board, I would suggest creating a class for holding all the Dimstyle settings and feeding that into the CreateModifyDimStyle method.

 

The main things I arrived at were :

-> The default DIMBLK, DIMBLK1, DIMBLK2 and DIMLDRBLK values ("." or "" when set using the DIMBLK command in Autocad) can be set using ObjectId.Null.

- > When you modify an existing dimension style and it is the current dimstyle, checking whether the modified style has the same ObjectId as the 'current' style will force an override to be created on that style.  This process was in an example I found.  See the comments in the 'SetDimStyleCurrent' code.

 

The main code blocks below are:

- CheckDimStyleExists  // Kind of redundant to my code now, but might be useful in the future

- CreateModifyDimStyle

- SetDimStyleCurrent

 

Some supporting methods used in those methods 

- GetLinestyleID

- CheckTextStyle

- CreateTextStyle

 

Just in case you are looking to get the Id of a linestyle other than "Continuous" (which can't be purged), there are a couple of methods that will check for its existence and load it from the nominated linetype file:

- CheckLineStyleExists

- LoadLineTypes

 

For those looking to get the ObjectId of arrow types other that the default (e.g. "_DOT", "_CLOSED", etc), the GetArrowObjectId pilferred from Kean Walmsley's blog will help out. Look up DIMBLK in the AutoCAD help for the appropriate values to pass it.

 

Anyway, I hope that this proves useful to someone and gives you something to work from.

 

Here's the code blocks.

 

BTW: I'm using 'static' to be a bit lazy and avoid creating an instance of the 'Utilities' class that contains the methods.  i.e. I simply need a reference to the containing dll (and namespace) and then I can use Utilities.<Method>.

 

The 'usings' at the top of my Utilities class are.  Some are relevant to these methods, some not.  Delete until something errors during compile.  Usually works for me  :smileytongue::

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Autodesk.AutoCAD; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Colors; using Autodesk.AutoCAD.LayerManager;

        

public static bool CheckDimStyleExists(string DimStyleName) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction tr = doc.TransactionManager.StartTransaction()) { DimStyleTableRecord dstr = new DimStyleTableRecord(); DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForRead, true); if (dst.Has(DimStyleName)) return true; return false; } }

 

public static void CreateModifyDimStyle(string DimStyleName, out string message) { // Initialise the message value that gets returned by an exception (or not!) message = string.Empty; try { using (Transaction tr = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()) { Database db = Application.DocumentManager.MdiActiveDocument.Database; DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForWrite, true); // Initialise a DimStyleTableRecord DimStyleTableRecord dstr = null; // If the required dimension style exists if(dst.Has(DimStyleName)) { // get the dimension style table record open for writing dstr = (DimStyleTableRecord)tr.GetObject(dst[DimStyleName], OpenMode.ForWrite); } else // Initialise as a new dimension style table record dstr = new DimStyleTableRecord(); // Set all the available dimension style properties // Most/all of these match the variables in AutoCAD. dstr.Name = DimStyleName; dstr.Annotative = AnnotativeStates.True; dstr.Dimadec = 2; dstr.Dimalt = false; dstr.Dimaltd = 2; dstr.Dimaltf = 25.4; dstr.Dimaltrnd = 0; dstr.Dimalttd = 2; dstr.Dimalttz = 0; dstr.Dimaltu = 2; dstr.Dimaltz = 0; dstr.Dimapost = ""; dstr.Dimarcsym = 0; dstr.Dimasz = 3.5; dstr.Dimatfit = 3; dstr.Dimaunit = 0; dstr.Dimazin = 2; dstr.Dimblk = ObjectId.Null; dstr.Dimblk1 = ObjectId.Null; dstr.Dimblk2 = ObjectId.Null; dstr.Dimcen = 0.09; dstr.Dimclrd = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 7); dstr.Dimclre = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 7); ; dstr.Dimclrt = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 2); ; dstr.Dimdec = 2; dstr.Dimdle = 0; dstr.Dimdli = 7; dstr.Dimdsep = Convert.ToChar("."); dstr.Dimexe = 1; dstr.Dimexo = 2; dstr.Dimfrac = 0; dstr.Dimfxlen = 0.18; dstr.DimfxlenOn = false; dstr.Dimgap = 1; dstr.Dimjogang = 0; dstr.Dimjust = 0; dstr.Dimldrblk = ObjectId.Null; dstr.Dimlfac = 1; dstr.Dimlim = false; ObjectId ltId = GetLinestyleID("Continuous"); dstr.Dimltex1 = ltId; dstr.Dimltex2 = ltId; dstr.Dimltype = ltId; dstr.Dimlunit = 2; dstr.Dimlwd = LineWeight.LineWeight025; dstr.Dimlwe = LineWeight.LineWeight025; dstr.Dimpost = ""; dstr.Dimrnd = 0; dstr.Dimsah = false; dstr.Dimscale = 1; dstr.Dimsd1 = false; dstr.Dimsd2 = false; dstr.Dimse1 = false; dstr.Dimse2 = false; dstr.Dimsoxd = false; dstr.Dimtad = 2; dstr.Dimtdec = 2; dstr.Dimtfac = 1; dstr.Dimtfill = 0; dstr.Dimtfillclr = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 0); dstr.Dimtih = false; dstr.Dimtix = false; dstr.Dimtm = 0; dstr.Dimtmove = 0; dstr.Dimtofl = false; dstr.Dimtoh = false; dstr.Dimtol = false; dstr.Dimtolj = 1; dstr.Dimtp = 0; dstr.Dimtsz = 0; dstr.Dimtvp = 0; // Test for the text style to be used ObjectId tsId = ObjectId.Null; // If it doesn't exist if(!CheckTextStyle("MR_ROMANS")) { // Create the required text style CreateTextStyle("MR_ROMANS", "romans.shx", 0); tsId = GetTextStyleId("MR_ROMANS"); } else // Get the ObjectId of the text style tsId = GetTextStyleId("MR_ROMANS"); dstr.Dimtxsty = tsId; dstr.Dimtxt = 3.5; dstr.Dimtxtdirection = false; dstr.Dimtzin = 0; dstr.Dimupt = false; dstr.Dimzin = 0; // If the dimension style doesn't exist if (!dst.Has(DimStyleName)) { // Add it to the dimension style table and collect its Id Object dsId = dst.Add(dstr); // Add the new dimension style table record to the document tr.AddNewlyCreatedDBObject(dstr, true); } // Commit the changes. tr.Commit(); } } catch (Autodesk.AutoCAD.Runtime.Exception e) { message = e.Message.ToString(); } }

 

public static void SetDimStyleCurrent(string DimStyleName) { // Establish connections to the document and its database Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; // Establish a transaction using (Transaction tr = doc.TransactionManager.StartTransaction()) { DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForRead); ObjectId dimId = ObjectId.Null; string message = string.Empty; if (!dst.Has(DimStyleName)) { CreateModifyDimStyle(DimStyleName, out message); dimId = dst[DimStyleName]; } else dimId = dst[DimStyleName]; DimStyleTableRecord dstr = (DimStyleTableRecord)tr.GetObject(dimId, OpenMode.ForRead); /* NOTE: * If this code is used, and the updated style is current, * an override is created for that style. * This is not what I wanted. */ //if (dstr.ObjectId != db.Dimstyle) //{ // db.Dimstyle = dstr.ObjectId; // db.SetDimstyleData(dstr); //} /* Simply by running these two lines all the time, any overrides to updated dimstyles get * cleared away as happens when you select the parent dimstyle in AutoCAD. */ db.Dimstyle = dstr.ObjectId; db.SetDimstyleData(dstr); tr.Commit(); } }

 

public static ObjectId GetLinestyleID(string LineStyleName) { ObjectId result = ObjectId.Null; Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { LinetypeTable ltt = (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForRead); result = ltt[LineStyleName]; tr.Commit(); } return result; }

 

public static bool CheckTextStyle(string TextStyleName) { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acDb = acDoc.Database; // Ensure that the MR_ROMANS text style exists using (Transaction AcTrans = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()) { TextStyleTableRecord tstr = new TextStyleTableRecord(); TextStyleTable tst = (TextStyleTable)AcTrans.GetObject(acDb.TextStyleTableId, OpenMode.ForRead, true, true); if(tst.Has(TextStyleName) == true) //if (tst.Has(tst[TextStyleName]) == true) return true; return false; } }

 

public static void CreateTextStyle(string TextStyleName, string FontName, double ObliqueAng, out string message) { try { using (Transaction transaction = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; TextStyleTable tst1 = (TextStyleTable)transaction.GetObject(db.TextStyleTableId, OpenMode.ForWrite, true, true); TextStyleTableRecord tstr1 = new TextStyleTableRecord(); tstr1.Name = TextStyleName; tstr1.FileName = FontName; tstr1.XScale = 0.8; tstr1.ObliquingAngle = Deg2Rad(ObliqueAng); tstr1.Annotative = AnnotativeStates.True; tst1.Add(tstr1); transaction.TransactionManager.AddNewlyCreatedDBObject(tstr1, true); transaction.Commit(); //RmTSid = tstr1.ObjectId; //return true; message = string.Empty; } } catch (Autodesk.AutoCAD.Runtime.Exception e) { message = e.Message.ToString(); } }

 

public static bool CheckLinestyleExists(string LineStyleName) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction tr = doc.TransactionManager.StartTransaction()) { //LinetypeTableRecord lttr = new LinetypeTableRecord(); LinetypeTable ltt = (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForRead, true); if (ltt.Has(LineStyleName)) return true; return false; } }

 

public static void LoadLinetypes(string LinFile, string LinType) { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Linetype table for read LinetypeTable acLineTypTbl; acLineTypTbl = acTrans.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead) as LinetypeTable; if (acLineTypTbl.Has(LinType) == false) { // Load the requested Linetype acCurDb.LoadLineTypeFile(LinType, LinFile); } // Save the changes and dispose of the transaction acTrans.Commit(); } }

 

static ObjectId GetArrowObjectId(string newArrowName) { ObjectId result = ObjectId.Null; Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; string oldArrowName = Application.GetSystemVariable("DIMBLK").ToString(); Application.SetSystemVariable("DIMBLK", newArrowName); if (oldArrowName.Length != 0) Application.SetSystemVariable("DIMBLK", oldArrowName); Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); result = bt[newArrowName]; tr.Commit(); } return result; }

 

Categories: AutoCAD Customization, Autodesk Forums

Converting AttributeDefinition objects to Text objects on Same Layer

AutoCAD Customization: Visual Basic Customization - Fri, 2013-05-10 06:50

 

Hello All,

 

I'm having an issue, and I'm hoping someone can give me a push in the right direction.

 

A little background first....

 

I have several .dwg files that I use as templates. I run find and replace VBA routines on the template .dwg files, ie find $Flavor$ and replace it with "Grape", and then I save the .dwg to another directory with a new name. 

 

These VBA routines work well for acdbText and acdbMText objects, but I have a bunch of AcdbAttributeDefinition objects in the .dwg templates as well.

 

After much research about the AutoCAD object model (I'm mostly a Microsoft Access VBA programmer), I have come to understand that these AcdbAttributeDefinition objects are actually "remnants" of a block that no longer exists in the drawing. Please, correct me if I'm misunderstanding this concept.

 

Anyway, I'd like to convert all of these orphaned AcdbAttributeDefinition objects to acdbText objects in the templates and then delete the AcdbAttributeDefinition objects. I have some code that does just that.

 

However, the issue that I am having with the code is that the newly created acdbText objects are not on the same layer that the original AcdbAttributeDefinition objects were on. I don't know the syntax to identify what layer the AcdbAttributeDefinition object is on or how to specify what layer on which the acdbText object is created.

 

Can anybody tell me how to keep the acdbText objects on the same layers as the original AcdbAttributeDefinition objects during the conversion and deletion process?

 

Here is the code I am using currently:

Sub AttConvert(dwg as string) Dim oDocument as AcadDocument Dim ent as AcadEntity Dim aa as object set oDocument = Documents.open(dwg) For Each ent In oDocument.ModelSpace If ent.ObjectName = "AcDbAttributeDefinition" Then ' DO SOMETHING TO IDENTIFY WHAT LAYER THE ACDBATTRIBUTEDEFINITION OBJECT IS ON
' DO SOMETHING TO SPECIFY THAT THAT IS THE LAYER TO CREATE THE ACDBTEXT OBJECT ON Set aa = ThisDrawing.ModelSpace.AddText(ent.TagString, ent.InsertionPoint, ent.Height) End If Next ent For Each ent In ThisDrawing.ModelSpace If ent.ObjectName = "AcDbAttributeDefinition" Then ent.Delete End If Next ent End Sub

 

 

Many Thanks,

Big D

Categories: AutoCAD Customization, Autodesk Forums

None of the get area scripts I have or searched for work in 2013. Dont know why

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Fri, 2013-05-10 04:47

I have one get area script I have used for the last few years in 2008-2009 autocad.  Now in 2013 all I get is ####. The script is suppose to get the area of a polyline and puts the number in a text field. I have searched online and found a few others that dont work in 2013 either.  I am wondering is it a setting I need to change in my 2013, or if the scripts really are not compatible.

 

;; local defun ;; get center of closed object (defun getcenter (obj / acsp cen rgn) (setq acsp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) rgn (car (vlax-invoke acsp 'Addregion (list obj))) cen (vlax-get rgn 'Centroid) ) (vla-delete rgn) cen ) ;; main part ;; label [plines w]/area field in sq. meters (defun c:larea (/ acsp adoc axss cpt ins ss txt mtxtobj) (vl-load-com) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (or acsp (setq acsp (vla-get-modelspace adoc ) ) ) (if (setq ss (ssget (list (cons 0 "*POLYLINE,*CONTOUR")))) (progn (setq axss (vla-get-activeselectionset adoc)) ;; iterate through the active selection set collection (vlax-for obj axss ; get a curve center (setq cpt (trans (getcenter obj) 0 1)) (setq txt ; displayed in meters to 3 decimal place: ;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId " ;;; (itoa (vlax-get obj 'ObjectID)) ;;; ">%).Area \\f \"%lu2%pr3%ps[, m2]%ct8[1e-006]\">%" ;;; ) ; displayed in engineering to 2 decimal place: (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get obj 'ObjectID)) ">%).Area \\f \"%pr2%lu2%ct4%qf1\">%");<--pr2 means 2 decimal places, change to your suit ; displayed in engineering to 2 decimal place with addition SQ. FT.: ;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId " ;;; (itoa (vlax-get obj 'ObjectID)) ;;; ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%") ); add mtext object to model space (setq mtxtobj (vlax-invoke acsp 'AddMText cpt ;insertion point 0.0 ; mtext width, optional = 0 txt ;string (field value) )) ; change mtext height accordingly to current dimension style text height: (vlax-put mtxtobj 'Height (getvar "dimtxt")); change (getvar "dimtxt") on text height you need ; set justifying to middle center (vlax-put mtxtobj 'AttachmentPoint acAttachmentPointMiddleCenter) ) ) ) (vla-regen adoc acactiveviewport) (princ) ) (princ "\n Type LAF to label objects with area field") (princ)

 

Categories: AutoCAD Customization, Autodesk Forums

DCL not closing

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Fri, 2013-05-10 03:00

I just can't figure this one out. Small little routine to calculate the total run of a PLINE (not complete, just starting it out) but from the dialog box, I want "CONTINUE" and "END" buttons. Continue will prompt user to select another 2 points to add. Original dialog box won't close to allow user input. What the heck am I not doing correct?

 

DCL:

 

TD : dialog {label = "Total Distance"; :edit_box {label = "Total distance: "; key = "DISTANCE";} :boxed_column {label = "Continue to add? "; :row { :button {label = "Continue"; key = "CONTINUE"; allow_accept = true;} :button {label = "End"; is_cancel = true;} } } }

 

LSP:

 

(defun C:TD () (setvar "CMDECHO" 0) (setq C-LAYER (getvar "CLAYER")) (defun PLINE-GEN () (setvar "ORTHOMODE" 1) (setq PT1 (getpoint "\nSelect first point: ")) (setq PT2 (getpoint PT1 "\nSelect second point: ")) (command "PLINE" PT1 PT2 "") ) (defun ADD-LINE () (unload_dialog dcl_id) (done_dialog) (term_dialog) (alert "Here we go again...") (setq PT3 (getpoint PT2 "\nSelect second point: ")) (command "PLINE" PT2 PT3 "") (DIA) ) (defun DIA () (setq dcl_id (load_dialog "TD")) (if (not (new_dialog "TD" dcl_id))(EXIT)) (progn (action_tile "CONTINUE" "(done_dialog)(ADD-LINE)") (if (= DIST-NUM nil)(set_tile "DISTANCE" "0")(set_tile "DISTANCE" DIST-NUM)) (mode_tile "accept" 2) (start_dialog) (unload_dialog dcl_id) ) ) (PLINE-GEN) (DIA) (setvar "CMDECHO" 1) (PRINC) )

 

Any help is GREATLY appreciated...

Categories: AutoCAD Customization, Autodesk Forums

Excel VBA to extract attrubutes from AutoCAD 2014

AutoCAD Customization: Visual Basic Customization - Fri, 2013-05-10 01:06

I have a program that I used years ago to extract attributes from AutoCAD into excel.   The VBA program is in excel.  It is Attribute extraction Utility for AutoCAD Release 14.   I want to use it again for 2014 but when I run it I get a compile error can't find project or library and it highlights the the following code "set doc = ACAD.ActiveDocument".   Can anyone help me fix this problem?    Below is the entire VBA sub routine.

 

' THIS EXTRACTS THE ATTRIBUTE VALUES FROM AUTOCAD TO EXCEL
Sub Extract()
Dim sheet As Object
Dim shapes As Object
Dim elem As Object
Dim Excel As Object
Dim Max As Integer
Dim Min As Integer
Dim NoOfIndices As Integer
Dim excelSheet As Object
Dim RowNum As Integer
Dim Array1 As Variant
Dim Count As Integer

Set Excel = GetObject(, "Excel.Application")
Worksheets("AcadAttr").Activate
Set excelSheet = Excel.ActiveWorkbook.Sheets("AcadAttr")
excelSheet.Range(Cells(8, 1), Cells(1000, 100)).Clear
excelSheet.Range(Cells(8, 1), Cells(1, 100)).Font.Bold = True
Set ACAD = Nothing
On Error Resume Next
Set ACAD = GetObject(, "AutoCAD.Application")
ACAD.Visible = True
Set doc = ACAD.ActiveDocument
Set mspace = doc.ModelSpace
RowNum = 8
Dim Header As Boolean
Header = False

Dim SelSet4 As Object
Dim pt1(0 To 2) As Double
Dim pt2(0 To 2) As Double
Set SelSet4 = doc.SelectionSets.Add("ss4")
pt1(0) = 87#
pt1(1) = 96#
pt1(2) = 0#
pt2(0) = 231#
pt2(1) = 160#
pt2(2) = 0#
SelSet4.Select acSelectionSetWindow, pt1, pt2

For Each elem In SelSet4
With elem
If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
If .HasAttributes Then
Array1 = .GetAttributes
For Count = LBound(Array1) To UBound(Array1)
If Header = False Then
If StrComp(Array1(Count).EntityName, "AcDbAttribute", 1) = 0 Then
excelSheet.Cells(RowNum, Count + 1).Value = Array1(Count).TagString
End If
End If
Next Count
RowNum = RowNum + 1
For Count = LBound(Array1) To UBound(Array1)
excelSheet.Cells(RowNum, Count + 1).Value = Array1(Count).TextString
Next Count
Header = True
End If
End If
End With
Next elem
NumberOfAttributes = RowNum - 1
If NumberOfAttributes > 0 Then
Worksheets("AcadAttr").Range("A8").Sort _
Key1:=Worksheets("AcadAttr").Columns("A"), _
Header:=xlGuess
Else
MsgBox "No attributes found in the current drawing"
End If
Set ACAD = Nothing
End Sub

Categories: AutoCAD Customization, Autodesk Forums

ActiveX Server Error in 2013 and 2014 VLA-ADD

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Fri, 2013-05-10 00:30

The following snippet works in 2012 but fails in 2013 and 2014

 

(if layer
        (progn
             (setq lays (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
                (if (vl-catch-all-error-p
                      (setq objlay (vl-catch-all-apply 'vla-item (list lays layer)))
                    )
                  (setq objlay (vla-add lays layer))
                )
        )
        (setq objlay (vla-get-activelayer (vla-get-activedocument (vlax-get-acad-object))))
   )

 

This line ...

(setq objlay (vla-add lays layer))

 

Returns:

error: ActiveX Server returned an error: Library not registered

 

Anyone have an idea what's wrong?

 

Thanks

Categories: AutoCAD Customization, Autodesk Forums

batch block attributes inputs

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 22:05

Greetings,

 

I have 40 pages in one set of drawings and would like to rev-up the drawings. i will put same texts in same locations in the title blocks. does anyone have the batch tool to do this batch inputs?

 

Thanks,

 

Peter

Categories: AutoCAD Customization, Autodesk Forums

Autodesk Add-In Question

AutoCAD Customization: .NET - Thu, 2013-05-09 21:05

I'm taking over the development of some Autodesk addins that are used to parse a drawing to bring back text from the drawing, namely title block and bill of materials information.  I have another process that runs and reads the meta data for the drawing itself that gets run from Vault before checking in the drawing.  I need to know if I can combine these two processes such that I can parse the drawing outside of AutoCad.  Is this possible?

Categories: AutoCAD Customization, Autodesk Forums

Is it possible to create a plugin like this?

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 21:02

Hi guys, I hope this goes to the right discussion group!

 

I have added a screenshot in the attachment illustrating my idea.

 

Would it be possible to create a (preferably semi-transparent) previously saved (preferably editable) list inside the autocad which would be tied to a user-defined button on the toolbar?

 

I know there is notepad, however it is a bit uncomfortable to use. What possibilities are there for creating something like that?

 

Regards,

Avo

Categories: AutoCAD Customization, Autodesk Forums

selection set continued

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 19:45

What I am trying to do is create a selection set of the "y" values of text.  I've started by pulling out all the text on the drawing, but I need it to continue to grab only the "y" values of the text on the drawing.

 

(setq alltext (ssget "_x"  (list '(0 . "TEXT")) 
        )  
    )     

 

I've tried a bunch of different things but I am still new to lisp.

Categories: AutoCAD Customization, Autodesk Forums

Simple Insert Macro-Will never prompt to REDEFINE block - 2012 LT

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 18:42

Greetings,

 

I am using 2012 LT so I don't have the luxury of LISP.

 

This simple macro works fine to insert the block "tofrom": 

 

^C^C-insert;k:/cad/customer/blocks/misc/tofrom;s;1;\0;

 

, however it will never prompt to Redefine the block if one exists in the drawing database. I am not sure if this can be done using DIESEL or not?

 

I would appreciate any input.

 

Thanks,

Doug

Categories: AutoCAD Customization, Autodesk Forums

Group center marks?

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 18:24

Anybody ever write a routine that would group center marks after using dimcenter?  Thanks.

Categories: AutoCAD Customization, Autodesk Forums

Export title block attribute text

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 15:03

Who you know how to export title block attribute text .. in a order from different layout .? file extn .xls or .txt  i got a tool named Autocad Automation tool .. but it not work very well

autocad have data extraction - its also came all text .. and not in order .. can we develop the any lisp for that ?..

 

Help me ... In Mail ID : Jamshi2000@gmail.com

Categories: AutoCAD Customization, Autodesk Forums

VBA Add document then Add layer got -2147418111 Automation error

AutoCAD Customization: Visual Basic Customization - Thu, 2013-05-09 07:34

Dear all,

 

   I got an error when add a layer after creating a new document, do you have any suggession?

 

Env.

Sub test() On Error GoTo err_handle Dim app As AcadApplication Dim sleepCount As Long Set app = GetObject(, "AutoCAD.Application") For i = 1 To 10 sleepCount = 0 app.Documents.add "acadiso.dwt" 'AddDrawingInfoLayer 'if I use this line directly,then will get an error: -2147418111 Automation error ' wait until the layer created, it's very slow, mornally it taks a long time to do it.. Do While AddDrawingInfoLayer = False sleepCount = sleepCount + 1 Wait 0.01' wait 0.01 second Loop Debug.Print i & " sleep " & sleepCount & " seconds" ThisDrawing.SaveAs "C:\temp\" & i & ".dwg" ThisDrawing.Close False Next i Exit Sub err_handle: Debug.Print Err.Number Debug.Print Err.Description End Sub Private Function AddDrawingInfoLayer() As Boolean On Error GoTo err_handle ThisDrawing.Layers.add "new_layer" AddDrawingInfoLayer = True Exit Function err_handle: AddDrawingInfoLayer = False End Function Private Function Wait(seconds As double) Dim varStart As Variant varStart = Timer Do While Timer < varStart + seconds Loop End Function

 

   Autocad 2013 64bit, windows 8 64bit. 8GB ram and i7-3770 cpu

 

Thanks in advance!

 

 

 

Categories: AutoCAD Customization, Autodesk Forums

AutoCAD.AcCmColor.18 not registered

AutoCAD Customization: Visual Basic Customization - Thu, 2013-05-09 04:11

My VBA stopped working on the following statement:

 

Dim RGB_Color As New AcadAcCmColor

 References to RGB_Color showed it to be Null.  Other posts referred me to a problem on 64-bit machines indicating I shoud add the following:

Set RGB_Color = GetInterfaceObject("AutoCAD.AcCmColor.18")

 However, that fails because AutoCAD.AcCmColor.18 is not in the registry.

 

My installation is AutoCAD Map 3D 2011.  How can I get that registered?

Categories: AutoCAD Customization, Autodesk Forums

Round Down Area of Polyline

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 03:12

I have a closed polyline that i can add the area to via a field in mtext using the options under area. I would like the area to always be rounded down to the nearest sqaure metre. Is the a way to do this via the acfields.fdc file? Or any other way?

 

Thanks, Patrick

Categories: AutoCAD Customization, Autodesk Forums

Need the Correct Way to Find Offset Origin of Layout

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 00:15

I want to know the correct way to find the offset origin of a layout in an AutoCAD drawing.  Let say I have a drawing that has many items on it.  And I create a layout showing just the items in the lower right corner of the drawing.  I want to know the offset origin of this layout relative to the Model space.

 

I came across some LISP commands that are supposed to do just that:

 

(vl-load-com) (setq activelayout (vlax-get (vla-Get-ActiveDocument (vlax-Get-Acad-Object)) 'ActiveLayout ) ) (setq activeplotorig (vlax-get activelayout 'PlotOrigin) )

 

Unfortunately, the commands don't seem to work because it always returns (0.0 0.0).  That cannot be right.

 

I am hoping that people can tell me what went wrong and show me the right way.

Thanks in advance.

 

Jay Chan

Categories: AutoCAD Customization, Autodesk Forums

how to draw triple or more lines

AutoCAD Customization: Visual LISP, AutoLISP and General Customization - Thu, 2013-05-09 00:08

hi

 

somebody can write me lisp code here for draw for example triple parallel line ? each line will be own layer and color..

 

thank you

Categories: AutoCAD Customization, Autodesk Forums

icons vs text

AutoCAD Customization: Visual Basic Customization - Wed, 2013-05-08 22:10

I no longer am able to switch my "anchored" tools from text to icons after upgrading to 2014. I migrated my 2013 settings, which were migrated from 2012, and it's always worked in the past, but now the option is grayed out. I've attached a screen shot to illustrate.

 

Is there a command I could do that would reset the ability to do this without losing my workspace settings?

 

Also, I have tried loading an "out-of-the-box" workspace and attempted to switch from text to icons and it too was grayed out.

 

Thanks in advance.

Categories: AutoCAD Customization, Autodesk Forums
  • « first
  • ‹ previous
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • …
  • next ›
  • last »

Individual forums:
- Visual LISP, AutoLISP and General Customization
- Visual Basic Customization
- Autodesk ObjectARX
- .NET

    © Copyright 2013 Autodesk, Inc. All Rights Reserved. Legal Notices & Trademarks - Privacy Policy

    Syndicate content