Trying to understand the shape import API in map better. Can anyone help? Specifically:
1) Can there be multiple tables? Better question, what are they? Compatible to anything else in the autocad api?
2) Does the layer name correlate with anything or is it just setting the actual autocad layer for the imported data?
3) For SetDataMapping, there's an option for "newobjectdataonly" and "existing...". What are these actually doing?
4) When I import a shape file it works fine. When I try to loop the import but switch the shape file I want to import it fails. I can't figure out if this has to do with the fact I'm using the same Importer.Init, or if I need to create a different table, layer, or do something with the data mapping.
Thanks you for the help if you can provide it.
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
Solved by norman.yuan. Go to Solution.
Let me try to comment to your questions as much as I can.
1. ObjectData table exists in AutoCAD Map drawing independently. When importing data with Map API, one can choose whether GIS data attributes would be imported as ObjectData or not. As for SHP, because each SHP file can only be one InputLayer in Map's Importer, thus, if you do import data attribute as ObjectData, then each each SHP importing would result in one ObjectData table with the table name being defaulted to the SHP file name. Obviously, it would be very rare one would import different set of GIS data from SHPs and the SHP files have the same file name. Also, since ObjectData exists in Map drawing independently regardless SHP data being imported or not, the drawing may already have a ObjectData table named the same as the SHP file name, which is to be imported. ObjectData is only available/valid in AutoCAD Map (and Civil3D, of course).
2. Importer is an IEnumerable object that may consist of one or more InputLayers. But since SHP can only contain one geometry type (polygon, point...), thus when importing SHP, the Import, after initialized, only has 1 InputLayer, which can be mapped to an existing AutoCAD layer. By default, the importer would create an AutoCAD layer names with the SHP file name.
3. As mentioned in 2, since there is possibility that the drawing may already have an ObjectData table with the name as SHP file name, by setting ImportDataMapping enum property, the Import would try to add ObjectData record to imported entities with existing OD table, or try to create a new OD table.
4. Since the Importer.Init(format, fileName), so, as you can see, if you import different SHP file, you MUST call Importer.Init() on each SHP. When Init() is called, AutoCAD Map reads the SHP data into Importer as InputLayer. Then you can manipulate the InputLayer for mapping AutoCAD layer, ObjectData...
Other thoughts:
Since you do the importing programmatically, you do not have to be limited with Map APIs for the ObjectData table naming, layer naming...
For example, you can examine the drawing for existing OD tables in drawing, to make sure no name conflict with possible SHP file names (thus default OD table names to be created by importing). And you can do the same with AutoCAD Layers.
You can also simply do the import without bothering ObjectData mapping/Layer mapping, and when the import is done, you can move the imported entities to whatever AutoCAD layer, and change the imported OD records as necessary. Of course, this would result in a lots of code. The point is that as programmer, you have the control to do things in different/multiple ways.
Hope this helps a bit.
Thank you again @norman.yuan you cleared everything up for me. Very much appreciated 🙂
"Obviously, it would be very rare one would import different set of GIS data from SHPs and the SHP files have the same file name."
@norman.yuan perhaps you can assist me with one more thing. This is the particular thing I'm trying to do. I'm trying to import data from the same shape file, but with a different locationoption. Struggling to figure out what I need to change in order for it not to fail (layername, tablename, importdatamapping, something else?)
Thanks!
It is still not very clear to me: when you say "import data from the same shape file, but with a different location option", do you mean perform the importing multiple times with each time only bringing in data of certain location option; or do you mean only import once, if possible, but only data within certain location/area scope would be brought in?
As my reply to your other post said, with AutoCAD Map's Import/Export API, you can only import entire SHP file. So if you only want portion of data from a big SHP file, you have to:
1. Import the SHP (all data, of course);
2. Remove unwanted data based on your "location option", which you can either done within pure AutoCAD operation (that is, loop through all imported entities, decide if one is wanted. If not erase it); or you can us AutoCAD Map's Query API to get all wanted data.
3. When doing the importing from the same SHP, you set ImportDataMapping to "NewObjectDataOnly" for first import (it is default, so you do not have explicitly set it); and for later importing, set it to "ExistingObjectData...".
But I'd rather do each importing with its default setting, and perform post-importing work, like:
1. after importing all data from the SHP, the entities imported are in a layer names as the SHP file name, and OD record attached with OD table names as the SHP file. The I'd loop through all imported entities to identify those wanted (based on "location options").
2. The identified entities will be moved to desired layer.
3. Unwanted entities will be erased.
4. Optional: I may also define an OD Table with different name and the same fields as the OD table generated by SHP import. The, create the OD record (with the same values as the imported OD record) on each entities. Then, I delete the OD table created by importing.
Each time you import from the same SHP into the same drawing, repeat the 1 to 3 steps with step 4 as optional.
Just my thought, and hope it gives you some ideas.
Thanks! Makes sense and helps a bunch, very much appreciated!!
Can't find what you're looking for? Ask the community or share your knowledge.