VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Country polylines

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Ray-Sync
335 Views, 2 Replies

Country polylines

Ray-Sync
Advocate
Advocate

Hello, do you know if it is possible to extract the georeferenced territorial limits of a country to import them into AutoCAD as polylines using VBA?

jefferson
0 Likes

Country polylines

Hello, do you know if it is possible to extract the georeferenced territorial limits of a country to import them into AutoCAD as polylines using VBA?

jefferson
2 REPLIES 2
Message 2 of 3
daniel_cadext
in reply to: Ray-Sync

daniel_cadext
Advisor
Advisor
Accepted solution

If you can use Python,  you may be be able to find something with geopandas

from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed
import traceback
import geopandas
 
def PyRxCmd_doit():
    try:
        db = Db.curDb()
        model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite)
        gdf = geopandas.read_file("E:/110m_cultural/ne_110m_admin_0_countries.shp")
    
        #do MultiPolygon first
        gdf0 = gdf.loc[gdf.geometry.geometry.type=='MultiPolygon']
        for mp in list(gdf0.geometry):
            for p in mp.geoms:
                pline = Db.Polyline(list(p.exterior.coords))
                pline.setColorIndex(1)
                pline.setClosed(True)
                model.appendAcDbEntity(pline)
 
        gdf1 = gdf.loc[gdf.geometry.geometry.type=='Polygon']
        for p in gdf1.geometry:
            pline = Db.Polyline(list(p.exterior.coords))
            pline.setColorIndex(2)
            pline.setClosed(True)
            model.appendAcDbEntity(pline)

    except Exception as err:
        traceback.print_exception(err)

 

theworld.png

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx

If you can use Python,  you may be be able to find something with geopandas

from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed
import traceback
import geopandas
 
def PyRxCmd_doit():
    try:
        db = Db.curDb()
        model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite)
        gdf = geopandas.read_file("E:/110m_cultural/ne_110m_admin_0_countries.shp")
    
        #do MultiPolygon first
        gdf0 = gdf.loc[gdf.geometry.geometry.type=='MultiPolygon']
        for mp in list(gdf0.geometry):
            for p in mp.geoms:
                pline = Db.Polyline(list(p.exterior.coords))
                pline.setColorIndex(1)
                pline.setClosed(True)
                model.appendAcDbEntity(pline)
 
        gdf1 = gdf.loc[gdf.geometry.geometry.type=='Polygon']
        for p in gdf1.geometry:
            pline = Db.Polyline(list(p.exterior.coords))
            pline.setColorIndex(2)
            pline.setClosed(True)
            model.appendAcDbEntity(pline)

    except Exception as err:
        traceback.print_exception(err)

 

theworld.png

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
Message 3 of 3
Ray-Sync
in reply to: Ray-Sync

Ray-Sync
Advocate
Advocate

Thank you, @daniel_cadext 

jefferson
0 Likes

Thank you, @daniel_cadext 

jefferson

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report