Recent Posts

Pages: [1] 2 3 ... 10
1
.NET / Re: Try Catch Finally Block Exception Error
« Last post by kdub on Today at 10:18:25 pm »
I use Autodesk.AutoCAD.Runtime.Exception

http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-A8D1137E-9283-4F1D-9B3E-89B90E5AA5A6

You may have the same issue with Application at times

I use this assignment
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
and use acApp in my code to to avoid confusion.

Good luck in your adventure :)
2
.NET / Try Catch Finally Block Exception Error
« Last post by sovby on Today at 10:01:48 pm »
I've been working on a tutorial that told me to add a try catch finally block. The catch(Exception ex) under the Lab 3 section just after instruction #8 is giving me an error that says 'Exception' is an ambiguous reference between 'System.Exception' and 'Autodesk.AutoCAD.Runtime.Exception'. It appears to be confused as to which exception to use but how do i go about fixing this? Here is my code:

// (C) Copyright 2016 by Microsoft
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;


// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(Lab2.MyCommands))]

namespace Lab2
{

    // This class is instantiated by AutoCAD for each document when
    // a command is called by the user the first time in the context
    // of a given document. In other words, non static data in this class
    // is implicitly per-document!
    public class MyCommands
    {
        // The CommandMethod attribute can be applied to any public  member
        // function of any public class.
        // The function should take no arguments and return nothing.
        // If the method is an intance member then the enclosing class is
        // intantiated for each document. If the member is a static member then
        // the enclosing class is NOT intantiated.
        //
        // NOTE: CommandMethod has overloads where you can provide helpid and
        // context menu.

        // Modal Command with localized name
        [CommandMethod("MyGroup", "MyCommand", "MyCommandLocal", CommandFlags.Modal)]
        public void MyCommand() // This method can have any name
        {
            // Put your command code here
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed;
            if (doc != null)
            {
                ed = doc.Editor;
                ed.WriteMessage("Hello, this is your first command.");

            }
        }

        // Modal Command with pickfirst selection
        [CommandMethod("MyGroup", "MyPickFirst", "MyPickFirstLocal", CommandFlags.Modal | CommandFlags.UsePickSet)]
        public void MyPickFirst() // This method can have any name
        {
            PromptSelectionResult result = Application.DocumentManager.MdiActiveDocument.Editor.GetSelection();
            if (result.Status == PromptStatus.OK)
            {
                // There are selected entities
                // Put your command using pickfirst set code here
            }
            else
            {
                // There are no selected entities
                // Put your command code here
            }
        }

        // Application Session Command with localized name
        [CommandMethod("MyGroup", "MySessionCmd", "MySessionCmdLocal", CommandFlags.Modal | CommandFlags.Session)]
        public void MySessionCmd() // This method can have any name
        {
            // Put your command code here
        }

        // Start of Lab2
        // 1. Add a command named addAnEnt. Use the CommandMethod attribute and a
        // Public void function.
        // Note: put the closing curley brace after step 21.
        [CommandMethod("addAnEnt")]
        public void AddAnEnt()
        {

         // 2. Declare an Editor variable named ed. Instantiate it using the Editor property
        // of the Application.DocumentManager.MdiActiveDocument.Editor
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

        // 3. Declare a PromptKeywordOptions variable and instantiate it by creating
        // a new PromptKeywordOptions. Use a string similar to the following for the
        // messageAndKeywords string.
        // "Which entity do you want to create? [Circle/Block] : ", "Circle Block"
            PromptKeywordOptions getWhichEntityOptions = new PromptKeywordOptions("Which entity do you want to create? [Circle/Block] : ", "Circle Block");

        // 4. Declare a PromptResult. Use the GetKeywords method of the Editor variable
        // created in step 1. Pass in the PromptKeywordOptions created in step 2. Instantiate
        // the PromptResult by making it equal to the return value of the GetKeywords method.
            PromptResult getWhichEntityResult = ed.GetKeywords(getWhichEntityOptions);

        // 5. Add an if statement that tests the Status of the PromptResult created in step 4.
        // Use the PromptStatus enum for the test. (see if it is equal to PromptStatus.OK)
        // Note: Move the closing curly brace after step 21.
        // (After the following instructions)
            if (getWhichEntityResult.Status == PromptStatus.OK)
            {

        // 6. PromptStatus was ok. Now use a switch statement. For the switch argument
        // use the StringResult property of the PromptResult variable used above
        // Note: Move the closing curly brace after step 21.
        // (Above the closing curly brace for the if statement in step 5)
        switch (getWhichEntityResult.StringResult)
        {


        // 7. Use "Circle" for the case. (if the StringResult is "Circle") Below
        // we will use "Block" for the case. (jump ahead to step 15 to add the break
        // to resolve the "Control cannot fall through... message")
            case "Circle":

        // 8. We want to ask the user for the center of the circle. Declare
        // a PromptPointOptions variable and instatiate it by making it equal
        // to a new PromptPointOptions. Use "Pick Center Point : " for message parameter
                PromptPointOptions getPointOptions = new PromptPointOptions("Pick Center Point : ");

        // 9. Declare a PromptPointResult variable. Use the GetPoint method of
        // the Editor created in step 2. (Pass in the PromptPointOptions created
        // in step 8). Instantiate the PromptPointResult by making it equal to the
        // return of the GetPoint method.
                PromptPointResult getPointResult = ed.GetPoint(getPointOptions);

        // 10. Add an if statement that tests the Status of the PromptPointResult
        // created in step 9. Use the PromptStatus enum for the test. (make sure it is OK)
        // Note: Move the closing curly brace right before step 15.
        if ((getPointResult.Status == PromptStatus.OK))
        {

        // Begining of Lab3. Create the Circle or Block and BlockReference
        // 1. Declare a Database variable and instantiate it
        // using the Document.Database property of the editor created above. (ed)
        // Note: Add the Autodesk.AutoCAD.DatabaseServices; namespace for Database
        // and Transaction, use the using keyword (above the class declaration)
            Database dwg = ed.Document.Database;

        // 2. Declare a Transaction variable; instantiate it using the
        // TransactionManager.StartTransaction method of the Databse
        // created in step 1.
            Transaction trans = dwg.TransactionManager.StartTransaction();

        // 3. Add a try, catch and finally block. Move the try closing curly
        // brace right after step 8. Put the catch statement after this.
        // Enclose  step 9 in the catch call. Enclose step 10 in the finally call.
        // (Build the project and fix any problems).
            try
            {


        // 4. Declare a Circle variable and create it using the new keyword.
        // Use the the Value property of the PromptPointResult created in
        // Lab2 for the first parameter. For the second parameter (normal) use
        // Vector3d.ZAxis. Use the Value property of the PromptDoubleResult
        // (created in Lab2) for the radius.
        // Note: Need to add Autodesk.AutoCAD.Geometry; namespace for Vector3d.

        // 5. Declare a BlockTableRecord variable. Instatiate it using the
        // GetObject method of the Transaction variable created in step 2.
        // Use the CurrentSpaceId property of the Database variable created in
        // step 1 for the first parameter. (ObjectId) For the second parameter
        // use OpenMode.ForWrite. We are adding the circle to either ModelSpace
        // or PaperSpace. (the CurrentSpaceId determines this)

        // 6. Add the Circle to the BlockTableRecord created in step 5. Use the
        // AppendEntity method and pass in the circle created in step 4.

        // 7. Tell the transaction about the new circle so that it can autoclose
        // it. Use the AddNewlyCreatedDBObject method. The first argument is the
        // circle. Use True for the second argument.

        // 8. Commit the transaction by calling the Commit method. If the code gets
        // this far everything should have worked correctly.
            }
            catch (Exception ex)
            {


        // 9. Declare an Exception variable for the Catch.
        // (add "(Exception ex)" to the catch keyword)
        // Use the WriteMessage of the Editor variable (ed) created in Lab2.
        // Use "problem due to " + ex.Message for the Message parameter.
        // If an error occurs the details of the problem will be printed
        // on the AutoCAD command line.
            }
            finally
            {

           

        // 10. Dispose the transaction by calling the Dispose method
        // of the Transaction created in step 2. This will be called
        //whether an error on not occurred.

            }
       
        // 11. Now we want to ask the user for the radius of the circle. Declare
        // a PromptDistanceOptions variable. Instatiate it by making it equal
        // to a new PromptDistanceOptions. Use "Pick Radius : " for the message parameter.
            PromptDistanceOptions getRadiusOptions = new PromptDistanceOptions("Pick Radius : ");

        // 12. We want to use the point selected in step 9 as the
        // base point for the GetDistance call coming up. To do this use
        // the BasePoint property of the PromptDistanceOptions variable created
        // in the previous step. Make the BasePoint equal to the Value property
        // of the PromptPointResult created in step 9.
            getRadiusOptions.BasePoint = getPointResult.Value;

        // 13. We need to tell the input mechanism to actually use the basepoint.
        // Do this by setting the UseBasePoint property of the
        // PromptDistanceOptions created in step 11 to True.
            getRadiusOptions.UseBasePoint = true;

        // 14. Get the radius for the circle. Declare a PromptDoubleResult variable.
        // Instantiate it using the GetDistance method of the Editor variable created
        // in step 2. Pass in the PromptDistanceOptions created in step 11 and
        // modified in the previous steps.
            PromptDoubleResult getRadiusResult = ed.GetDistance(getRadiusOptions);
        }
        // 15. Add break to mark the end of the code for the "Circle" case.
        break;
        // 16. Add the Case for the "Block" (jump ahead to step 20 to add the break
        // to resolve the "Control cannot fall through... message")
            case "Block":

        // 17. Now we want to ask the user for the name of the block. Delcare
        // a PromptStringOptions varable and instatiate it by creating a new
        // PromptStringOptions. Use "Enter name of the Block to create : " for
        // the message parameter.
        PromptStringOptions blockNameOptions = new PromptStringOptions("Enter name of the Block to create : ");

        // 18. No spaces are allowed in a blockname so disable it. Do this by setting
        // the AllowSpaces property of the PromptStringOptions created in step 15
        // to false.
        blockNameOptions.AllowSpaces = false;

        // 19. Get the name the user entered. Declare a PromptResult variable
        // and instantiate it using the GetString method of the Editor object
        // created in step 2. Pass in the PromptStringOptions created in step 17.
        PromptResult blockNameResult = ed.GetString(blockNameOptions);

        // 20. Add break to mark the end of the code for the "Block" case.
        break;

        // 21. Build the project. Place a break point. Use the NETLOAD command
        // and run the AddAnEnt command. Step through the code and fix any errors.
        // Remember to run the command and test the code for both circle and block.
        // End of Lab2
            }
            }
        }
        // LispFunction is similar to CommandMethod but it creates a lisp
        // callable function. Many return types are supported not just string
        // or integer.
        [LispFunction("MyLispFunction", "MyLispFunctionLocal")]
        public int MyLispFunction(ResultBuffer args) // This method can have any name
        {
            // Put your command code here

            // Return a value to the AutoCAD Lisp Interpreter
            return 1;
        }

    }

}
3
The Third Dimension / Blend 2 solids at edge
« Last post by kdub on Today at 09:58:37 pm »
I'm wondering if I've forgotten something ....

I needed to blend adjacent solids (representing steel plates).
Currently I'm using some code I've written to query the complimentary dihedral angle for the plate edges, divide it by 2 and add that value to the clipboard in code.
Then I apply a taper manually to each edge using the value on the clipboard for the taper angle.

I'm wondering if there is a built in command I've missed to do this process .

Here's a ToDo and a DonePreviously piccy to help visualise the product.

added for the inquisitive :
The assembled petals represent the facets of a square to round transition chute.
The petals are flat rather than conical because they will have flat removable wear plates bolted inside to protect the chute walls from the abrasive product.
Each of the crease line will be 'pressed' on the wall plate.


Regards,
4
CAD General / Re: Modify Text Height in Tables created in Autocad 2017
« Last post by ParamG on Today at 09:12:04 pm »
Thanks Jeff.This is what I did before you replied and it works
1. Select Table
2. Click on Top left corner and Right click , select Properties and Modify  Text Height in "Content" Voila, it will change height in Entire Table.
3. Then You can Modify Text Height in Title and Header individually, makes it so easy

"You will never know until you try"  :idea:
5
AutoLISP (Vanilla / Visual) / Re: Triangulation (re-visited)
« Last post by ymg on Today at 06:40:46 pm »
Rick,

I did a few test and I could not replicate the behaviour
you are experiencing.

However if your boundary is not exactly on the nodes
you will have something like what you describe.

As it is the bound function is not too good, the following is
a little better.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:bound (/ sp tmp)
  2.   (setq oldosm (getvar 'OSMODE))
  3.   (if (not csurf) (setq csurf "Natural Ground"))
  4.   (if (/= "" (setq tmp (getstring (strcat "\nCreates a Boundary for TIN <" csurf ">: "))))
  5.     (setq csurf tmp)
  6.   )
  7.   (mk_layer (list "Boundary" 2))
  8.  
  9.   (setvar 'OSMODE 8)
  10.   (prompt "\nSelect Points on Boundary: ")
  11.   (command "_3DPOLY"  pause )
  12.     (while (command pause))  
  13.   (setq *bounden* (entlast))
  14.   (setvar 'OSMODE oldosm)
  15.   (princ)
  16. )
  17.  
6
AutoLISP (Vanilla / Visual) / Re: Triangulation (re-visited)
« Last post by ymg on Today at 05:20:52 pm »
Rick,

Could be a bug as this was put together quite fast.

But as I told you, I am only using centroid of triangles
and ptinpoly_p to check if the centroid is inside the polyline

I will have a look at it.

ymg
7
AutoLISP (Vanilla / Visual) / Re: Triangulation (re-visited)
« Last post by rw2691 on Today at 05:13:52 pm »
YMG,

When I use your current Centroid routine it does not delete external TIN's that have only one corner touching the Boundary, and it does not delete any TIN's that are detached and beyond the Boundary. Leaving the user to manually delete them one by one.

The OCD does delete them. It doesn't miss any TIN that is outside, and it protects all that are inside.

Rick
8
AutoLISP (Vanilla / Visual) / Re: Triangulation (re-visited)
« Last post by ymg on Today at 04:21:48 pm »
Rick,

I will look at it.  But the centroid of a triangle
is guaranteed to be inside.

The routine to check if that centroid is in the
polyline is ptinpoly_p and I've checked it quite
extensively.

A simplification of this would be to check if the
biggest polyline in bp contains all the point of the
triangulation. If so we would trim the exterior,
else if it has no point within we trim the inside.

This way we remove the necessity to assign the
outside boundary to a layer in order to recognize it.

Now I look at your modification.  To make it work with TIN
you simply need to update tl by removing any triangle that you
are deleting.  You do the same with 3dfl removing the ENAME
of  any 3DFACES you delete.

This snippet does it:

Code - Auto/Visual Lisp: [Select]
  1. (setq tr (list
  2.                   (vl-position  (car   tp) pl)
  3.                   (vl-position  (cadr  tp) pl)
  4.                   (vl-position  (caddr tp) pl)
  5.            )
  6.         tl (vl-remove tr tl)
  7.      3dfl (vl-remove en 3dfl)
  8.       ** (entdel en)
  9. )
  10.  



ymg
9
AutoLISP (Vanilla / Visual) / Re: Triangulation (re-visited)
« Last post by rw2691 on Today at 03:51:07 pm »
YMG,

I would like you to look at how I modified the OCD code. It virtually clips all 3dfaces that are outside the Boundary. Nothing is missed. It also is not using a Centroid model, which can fall outside the body of the Boundary. It is work your examination. Please test it.

Rick
10
AutoLISP (Vanilla / Visual) / Re: Triangulation (re-visited)
« Last post by ymg on Today at 03:31:36 pm »
Rick,

I had OCD in the code in prior version but never used it.

Right now, I am processing the outside boundary as well as
the holes with the following code:

Code - Auto/Visual Lisp: [Select]
  1. ;;                                                             ;
  2.               ;; Erasing Triangles in Holes of Triangulation, and those      ;
  3.               ;; Outside of the boundary. Adjusting Triangle List.           ;
  4.               ;;                                                             ;
  5.               ;; Notes: This is a fast hack where we select 3Dfaces with a   ;
  6.               ;;        Crossing Polygon then Computes their Centroid and    ;
  7.               ;;        remove those whose centroid is inside the poly.      ;
  8.               ;;                                                             ;
  9.               ;;        Will change it eventually to offset the polyline     ;
  10.               ;;        to the outside by a few millimeters, and make the    ;
  11.               ;;        Selection by Window Polygon.                         ;
  12.               ;;                                                             ;
  13.               ;; Modified to handle external boundary   November 2015        ;
  14.               ;;                                                             ;
  15.  
  16.               (vl-cmdf "_ZOOM" "_E")
  17.               (if *bounden*
  18.                  (setq bp (distinct (mapcar '(lambda (a) (list (car a) (cadr a))) (listpol *bounden*))))
  19.               )
  20.               (foreach wp wpl
  21.                  (setq  ss (ssget "_CP" wp '((0 . "3DFACE"))))
  22.                  (repeat (setq i (sslength ss))
  23.                     (setq  en (ssname ss (setq i (1- i)))
  24.                           ent (entget en)
  25.                            tp (list (cdr (assoc 11 ent))
  26.                                     (cdr (assoc 12 ent))
  27.                                     (cdr (assoc 13 ent))
  28.                               )
  29.                            ct (centroid tp)
  30.                            in (ptinpoly_p ct (cons (last wp) wp))
  31.                     )
  32.                     (if (or
  33.                             (and in (not (equal wp bp)))
  34.                             (and (not in) (equal wp bp))
  35.                          )
  36.                         (setq tr (list (vl-position  (car   tp) pl)
  37.                                        (vl-position  (cadr  tp) pl)
  38.                                        (vl-position  (caddr tp) pl)
  39.                                  )
  40.                               tl (vl-remove tr tl)
  41.                             3dfl (vl-remove en 3dfl)
  42.                               ** (entdel en)
  43.                         )
  44.                     )
  45.                  )
  46.  
  47.  
Pages: [1] 2 3 ... 10