PDA

View Full Version : AutoCad C3D - Trying to Automate MAPEXPORT to include Attribute Data from data table



lmorse757798
2021-01-25, 04:40 AM
Hi,
I have 3 drawings, each with 50+ layers. The client wants me to export each individual layer as an individual SHP file, and needs me to run the export every couple of months. I can write up a script file specifying each layer etc, the catch is that I also need to export the Attribute Data from the attached data tables for each item. I cannot seem to get a hook into the Attribute Data\Object Data using the MAPEXPORT command in a script, e,g:


-mapexport" "SHP" "c:\\Temp\\MyLayer1.shp" "Y" "c:\\Temp\\Street.epf" "S" "L" "All" "MYLAYER1" "*" "No" "Proceed"
-mapexport" "SHP" "c:\\Temp\\MyLayer2.shp" "Y" "c:\\Temp\\Street.epf" "S" "L" "All" "MYLAYER2" "*" "No" "Proceed"
This will export my layers, but minus the Attribute Data from the attribute table.

Does anyone have experience in doing this kind of export to SHP? Is it possible to script, or code so that the shapefile contains the Attribute Data?

I tried something along the lines of:


-mapexport" "SHP" "c:\\Temp\\MyLayer2.shp" "Y" "c:\\Temp\\Street.epf" "S" "L" "All" "MYLAYER2" "*" "No" "D" "MyDataTable" "Proceed"
But this was just a stab in the dark, I cannot find any documentation outlining the datatable in the command line use of MAPEXPORT.

Note: I can export the shapefile manually and select the data table and it exports as I need it to (by selecting the Data tab in the export dialogue).

I have very limited knowledge of Lisp.

I hope I have explained my issue well enough. Thanks for any help.

Opie
2021-01-26, 03:38 PM
The Data option of the -mapexport command does not ask for the data table to use. That is defined in your loaded profile. Your loaded profile can also set the selection to all on the specific layer.

If you want to understand a bit more on your profiles, open one in an XML file viewer/editor.

See if this works for you. You will need to adjust the strings for the storage and profile paths. This code will only export layers that have an associated profile saved. Each profile has the selection type set to all of the object types (i.e.: Point, Line, Polygon, or Text) for that layer and the data table associated with that layer.


(defun c:ExportToShp (/ sStoragePath sProfilePath)
(setq sStoragePath "C:\\Temp\\SHP\\Data\\"
sProfilePath "C:\\Temp\\SHP\\Profiles\\"
)
(vlax-for n (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
(if (and (findfile (strcat sProfilePath (vla-get-name n) ".epf"))
(not (findfile (strcat sStoragePath (vla-get-name n) ".shp")))
)
(command "-mapexport"
"SHP"
(strcat sStoragePath (vla-get-name n) ".shp")
"Y"
(strcat sProfilePath (vla-get-name n) ".epf")
"P"
)
)
)
)