May 2012

05/31/2012

To turn on or off the running osnap, simply set the SNAPMODE system variable to 1 or 0.

Here is a sample code :

// Turn-off running osnap

Application.SetSystemVariable("SNAPMODE", 0);

// Turn-on running osnap

Application.SetSystemVariable("SNAPMODE", 1);

The various osnap options are governed by the value of the OSMODE system variable. Here is a post that describes setting of the OSMODE system variable. The values that the OSMODE system variable can take can be found in the AutoCAD documentation.

Prior to AutoCAD 2009, If object snap (Osnap) is turned off, AutoCAD adds 16384, to the current setting for the variable OSMODE. This allows applications to identify the current setting for OSMODE.

For instance, when you activate the "endpoint" object snap and Osnap is enabled, OSMODE contains 1 as its value. If object snap is disabled, OSMODE will contain 16385 as its value (1 + 16384).

It is tempting for a Visual LISP developer to supply list arguments for the parameters filtType and filtData in the vla-select call, but ActiveX does not comprehend lists. The filtType parameter requires an array of integers while filtData is permitted to be a array of variant types.

For a closer examination of safearrays and variants, see the Visual LISP Developer's Guide. Refer to the section entitled "Converting AutoLISP Data Types to ActiveX Data Types".

Also, the group code designating xdata is 1001 instead of -3. This is different, of course, from the Visual LISP approach to filtering xdata, which makes use of the -3 extended data sentinel rather than group code.

An AutoCAD setting in the Options dialog controls behavior of adding a viewport to new layouts. You can turn off the creating viewports in newly created layouts. You can find the setting along this path:

05/30/2012

In part 1 of this series I created a simple task list prioritization tool for AutoCAD written in C#. This was based on two classes: Item and PrioritizerCore.

In part 2, I setup an Android app project in Eclipse, and migrated my Item class from C# to Java, discovering how very similar the two languages are.

Today, I'll migrate the PrioritizerCore class. (As for the Item class, the goal today is to get the code to compile in Eclipse - we'll check the logic still works when we hook the classes into a working Android app).

We'd already copied the PrioritizerCore C# code into a PrioritizerCore.java file in our Android project, so we can just jump in and start editing. Before making additional changes, we'll go through the code and make the same edits as we did for Item without further comment:

Change string to String and bool to boolean.

Change LIst to ArrayList.

Change the Serializable attibute to the Java Serializable interface.

Change properties to get/set methods, and change calls to properties in the same way.

Change all function names to start with a lowercase character instead of uppercase.

USe intellisense to reference missing packages.

That removes the vast majority of compilation errors. Those that remain are new.

The first new error we encounter is the foreach loop - which is really handy for iterating the elements of a collection. The C# code looks like this:

foreach (Item i in m_ItemList)

Java has an equivalent, but the syntax is slightly different. We change that line to:

for (Item i : m_ItemList)

which I really like - its even more succinct than the C# :-).

The next error is:

public void sort(){m_ItemList.sort(new ItemComparer());}

Again Java has an equivalent of the sort method and the equivalent of a Comparator. We change our code to:

public void sort(){Collections.sort(m_ItemList, new ItemComparer());}

As you'd expect, the next error is in our custom comparator definition. We change

private class ItemComparer : IComparer<Item>

to

private class ItemComparer implements Comparator<Item>

And that's it. No more errors.PrioritizerCore.java now looks like this:

//Adds a new Item to the list // but only if the name (ItemText) is uniquepublic boolean addItem(String strItemText){Item tmpItem = new Item();tmpItem.setItemText(strItemText);if (m_ItemList.contains(tmpItem))return false;

//Read-only property//Returns number of items in the listpublic int getItemCount(){return m_ItemList.size();}

//Returns true if any priorities have been set in list//(Which also means there must be at least two items in the list)public boolean hasPriorities(){for (Item i : m_ItemList){if (i.getScore() > 0){return true;}}return false;}

//Sort in order of descending Score. //If Result is same, sort on ascending Text.private class ItemComparer implements Comparator<Item>{public int compare(Item x, Item y){//If items have same prioritization score, use prioritization// between the two items to sort. If that doesn't work, sort// alphanumerically on ItemText.if (x.getScore() == y.getScore()){

If there are multiple model-space viewports and to switch to a single model-space viewport configuration, you could use the -VPORTS command and specify the SI option.

For example :

acedCommand(RTSTR, L".-VPORTS", RTSTR, L"SI", RTNONE);

The other way to do this is to erase the viewport table records. When there are multiple model space viewports, you will find the same number of viewport table records in the viewport table. They all have the same name. To switch to a single viewport, all the viewports except one may be erased and the last remaining viewport can be set to cover the whole area.

To create anonymous Layer, you need to call “AcDbLayerTable::setIsHidden()” API as shown in below code. Anonymous layers are not shown in layer manager and hence users can not edit/delete the setting of anonymous layers.

For converting Polyline2d to Polyline, you can use Polyline.ConvertFrom API. But this API throws the eInvalidContext exception when the second argument for ConvertFrom() is set to true, inside the transaction. The true argument will handover the same object Id's to the new entity. This is fine except for a rule that AcDbObject::handOverTo() (defined in ObjectARX) cannot be used inside of a transaction. So, to solve issue, use Open and Close technology as shown in below code.