AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

InputLayer Style after do an importer

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
imago69_
902 Views, 8 Replies

InputLayer Style after do an importer

Hello,

 

I am new in AutoCad Map development. I am developing a .NET command which imports a Shape into AuotCad Map.

 

After import my shape using Autodesk.Gis.Map.ImportExport.Importer class, I want to change the visibility of the imported layer of the shape (which is an InputLayer).

 

How can I do this?

8 REPLIES 8
Message 2 of 9
norman.yuan
in reply to: imago69_

InputLayer.Name is the AutoCAD Layer the imported shape data's geometry would be sit on.

 

So, after the importing, you simply find the AutoCAD layer and turn it on/off.

 

Here is quick code off my head:

 

Document dwg=Application.DocumentManager.MdiDocument;

 

using DocumentLock dl-dwg.LockDocument()

using (Transaction tran=dwg.TransactionManager.StartTransaction())

{

    LayerTable lt=(LayerTable)tran.GetObject(dwg.Database.LayerTableId,OpenMode.ForRead);

    if (lt.Has(TheLayerName))

    {

        LayerTableRecord lr=(LayerTableRecord)tran.GetObject(lt[TheLayerName],OpenMode.ForWrite);

        lr.IsOff=true; //turn it off

    }

    tran.Commit();

}

 

HTH

Message 3 of 9
imago69_
in reply to: norman.yuan

Sorry, what I want to change is the transparency.

 

Thanks!

Message 4 of 9
norman.yuan
in reply to: imago69_

Now that you know how to get the AutoCAD layer, you are free to change the layer's Transparency property as you wish, something like:

 

myLayer.Transparency=new Autodesk.AutoCAD.Colors.Transparency(Convert.ToByte([0 - 255]));

Message 5 of 9
imago69_
in reply to: norman.yuan

It allowa me to change the layer transparency, but it doesn´t change in the entity of the shape.

 

When I load the shape, in the AutoCad Map "Properties" menu, tab "Design", layer "MyLayer" I can see the layer with the new line height (the one I put by code)

 

But, when I select my entity from the loaded shape, the attribute is "EntityTransparency", and this one is what I want to change.

 

 

Message 6 of 9
norman.yuan
in reply to: imago69_

What is the imported entity's Transparency property? Shouldn't it be "ByLayer" (which means whatever the Transparency of a layer changes, the entities' also change visually (while its value remains as "ByLayer")?

 

I never needed to change layer/Entity Transparency in my development work, but just a thought:

 

If you want to import the data into an existing AutoCAD layer, then you can name the InputLayer's name to that layer, and before importing, you set that layer to the desired Transparency.

 

Or, if you let Importer to create a new layer, then after the importing, you first set the layer's Transparency, then you select all entities on that layer (use Editor.SelectAll([layer filter])) and loop through the entities and set their Transparency to "ByLayer" or whatever value you wish.

Message 7 of 9
imago69_
in reply to: norman.yuan

The the imported entity's Transparency property is the name of the property which appears in AutoCad Map when I select the entity.

 

I think that the logical functionality is that the transparency of all the entities in the shape imported change when you change the transparency of the layer, but it doesn't work.

 

However, if I change the LineWeight property of the layer it changes it...

Message 8 of 9
norman.yuan
in reply to: imago69_

After importing, the imported entity's Transparency should be "ByLayer", meaning whatever the layer's Transparency is, the enitity's Transparnecy would be the same as the layer's.

 

So, I do not know what happens in your case. Just to verify it again, I did following quick code test:

 

using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Gis.Map;
using Autodesk.Gis.Map.ImportExport;


[assembly: CommandClass(typeof(ImportShapeToMap.ShapeImportCommands))]

namespace ImportShapeToMap
{
    public class ShapeImportCommands
    {
        [CommandMethod("ImpShp")]
        public static void ImportShapeData()
        {
            string shapeFile = @"D:\Work\Acad\Map GIS Data\SHP Data\pipeline.shp";

            MapApplication mapApp = HostMapApplicationServices.Application;
            Importer importer = mapApp.Importer;

            try
            {
                importer.Init("SHP", shapeFile);
                foreach (InputLayer layer in importer)
                {
                    // Do this in second test: to import shape data into an existing
                    // layer with transparency = 50%
                    ////layer.SetLayerName(LayerNameType.LayerNameDirect, "Layer1");
                }

                importer.Import(true);

                MessageBox.Show("Importing completed!");
            }
            catch (MapImportExportException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

 I ran the code twice:

 

1. commented out the code inside the foreach... loop. In this test, the importer will create a default import layer ("pipeline") with Transparency set to 0%. After importing, all entities imported has their Transparency value set to "ByLayer". Change the layer's Transparency will also change the entities' Transparency VISUALLY (but the value is still "ByLayer", of course).

 

2. uncomment the code inside "foreach...", so that the entities will be imported into an existing layer, called "Layer1" with Transparency set to 50%. After importing, all entities imported still has their Transparency valye set to "ByLayer", and they VISUALLY show 50% transparency, as the layer is set to.

 

So, I assume when entities is created by the Importer, most of their properties would be set to "ByLayer", if the property has this option.

 

Are you saying that in your case the entities imported have Transparency value set to something other than "ByLayer"?

Message 9 of 9
imago69_
in reply to: norman.yuan

In my case it appears a layer which the name I put fir it, and its Transparency value is set to "ByLayer".

 

I understand that this is correct.

 

But, how can I change the transparency of this imported layer?

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost