Ad

Tuesday, October 17, 2017

Style Changes

Have you ever wanted to change styles quickly? Maybe you want go from OldStyle to NewStyle, but don’t want to do it manually. Well here is maybe one way to quickly change styles for lots of objects using a LispFunction. A LispFuntion allows Lisp to talk to .NET.

In this case we can use fancy inheritance to set the style name of any object type we want. We do this by using the fact that most Civil 3D objects are a type of Autodesk.Civil.DatabaseServices.Entity which contains the StyleName property. Luckily this property takes a string and Civil 3D takes care of finding the correct style to use based on the name given. If the style isn’t in the drawing an exception will occur and an error message sent to the command line.

After loading the dll you can then type at the command line:

(ChangeCivil3DStyleByName “AECC_ALIGNMENT” “OldStyleName” “NewStyleName”)

Then press enter. Then each alignment with the OldStyleName will be magically changed to the NewStyleName. If you have lots of objects to change I’d build a list in Excel with the appropriate object type and style names and use the Concatenate formula to build the above lines. Then you can add it to a lisp or copy and paste at the command line.

To get the object type names (like AECC_ALIGNMENT), select the object and then type List at the command line. The first line should give you the value.

public class StyleChanges

{

     [LispFunction("ChangeCivil3DStyleByName")]

     public void ChangeStyleName(ResultBuffer rbArgs)

     {

          if (rbArgs == null) {

          Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nNo objects passed");

     }

     var rbArgsList = rbArgs.AsArray().ToList();

     if (rbArgsList.Count() != 3)

     {

          Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nNeed three objects to be passed.");

     }    

     try

     {

          var civDoc = CivilApplication.ActiveDocument;

          var objectType = rbArgsList[0].Value.ToString();

          var oldStyleName = rbArgsList[1].Value.ToString();

          var newStyleName = rbArgsList[2].Value.ToString();

          // Aec.DatabaseServices.Entity

          var doc = Application.DocumentManager.MdiActiveDocument;

          var ed = doc.Editor;

          using (var tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())

          {

               // Need to get the objects

               TypedValue[] vals = new TypedValue[]

               {

                    new TypedValue((int)DxfCode.Start, objectType)

               };

               var res = ed.SelectAll(new SelectionFilter(vals));

               if (res.Status == PromptStatus.OK) { foreach (ObjectId objId in res.Value.GetObjectIds())

               {

                    var aecObj = objId.GetObject(OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Entity;

                    if (aecObj.StyleName == oldStyleName)

                    {

                         aecObj.UpgradeOpen();

                         aecObj.StyleName = newStyleName;

                    }

               }

         }

    tr.Commit();

}

}

catch (System.Exception ex) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nError: " + ex.Message); } } }

Tuesday, August 15, 2017

Property Set Formulas

Sometime in the recent past Autodesk enabled and advocated the use of Property Sets. It’s kind of sad why Autodesk did this, but that is another story about the lack of BIM in Civil 3D. I recently learned one can create formulas in the Property Sets and use VBScripts in the formulas. We can then use these scripts to extract information from objects. In this post I’m going to show how you can create a script to show a Pipe’s Material.

The first step is to type PropertySetDefine at the command line. This will bring up the Style Manager. image

Right click on the Property Set Definitions and select the New option. I’m using the default name of New Style. In the script I will want to use the ObjectID of the object. Note that this ObjectID is different than ObjectId found in .NET. To add this property click on the Applies To tab of the Property Set Definition select Pipe.

image

Then press the Add Automatic Property Definition button and select Object ID from the list.

image

We will need this property in the script. So now we can create a script. Note that if you don’t want to see the property in the Properties palette you can check the Visible check box to unchecked.

image

Now press the Add Formula Property Definition button. Then Right Click, in the Insert Property Defintions, on the ObjectID and select Insert. This will add the ObjectID to the formula box and in the Enter Sample Values list.

image

Next insert the following formula in the formula box. Remove the [ObjectID] from the previous step. Make sure each line

RESULT="—"

On Error Resume Next

Set oApp=GetObject(, "AutoCAD.Application")

Set oCivilApp=oApp.GetInterfaceObject("AeccXUiLand.AeccApplication.11.0")

Set obj=oCivilApp.ActiveDocument.ObjectIdToObject("[ObjectID]")

RESULT=obj.PartDataRecord.FindByContext(300).Tag

If the text ends up large press OK and then go back into the dialog box. This will reset the text height to the default size. Then go into the drawing and apply the property set by selecting a pipe and pressing the Add Property Set button.

image

Then the Material name should show up in the box.

image

You can find the list of standard Context here: http://blog.civil3dreminders.com/2016/03/freaking-context-values.html if you want to use a different value.

Here is a video showing the steps: https://www.youtube.com/watch?v=v97WpUgk0w8

Saturday, July 22, 2017

Some Tips

This post won’t make sense unless you want to add a block at each circle and then to go back in and renumber the blocks.
Renumber blocks Lisp from Cad Forum powered by CadStudio.
Lisp Function to add a block at selected circles. (Based on this post)
To load the lisp functions for Mac.
To create blocks with attributes for Mac.

Another renumber lisp that should work on Macs. The first one doesn't work since VLX isn't supported on Macs.

Tuesday, July 18, 2017

Migrate Settings

So you want to migrate settings according to this AKN article. Unfortunately Civil 3D doesn’t include the shortcut as indicated in the file. The easy way to run the Migrate program is to navigate to the program and run it directly.

The location of the program is here:

C:\Program Files\Autodesk\AutoCAD 2018\AdMigrator.exe

If you want the same experience as the article you can follow these steps:

  • Right click on the desktop and choose New, then Create Shortcut.
  • A dialog box should pop up where you can enter the location of the item:
    C:\Program Files\Autodesk\AutoCAD 2018\AdMigrator.exe
  • Press Next and give the shortcut a name and press finish.
  • Select the newly created shortcut, right click and go to properties.
  • In the Target box enter in the string:
    "C:\Program Files\Autodesk\AutoCAD 2018\AdMigrator.exe" /product "C3D" /language "en-US"
  • Copy and paste the shortcut to start menu where it should be located in the AKN article.

Tuesday, May 16, 2017

Statistics Tab

This post shows how to get the Statistics Tab back in Windows File Properties. The first step is to type Default Programs at the Windows Start Menu.

image

Then select Choose default apps by file type.

image

Then select the AutoCAD DWG Launcher as the app to launch DWG files.

image

Now the Statistics Tab will show up.

image

LinkWithin

Blog Widget by LinkWithin

Ad