Skip to content

entity

DmDataTable

数据表 Python 二次封装类

Source code in dimine_python_sdk\lib\types\entity.py
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
class DmDataTable:
    """
    数据表 Python 二次封装类
    """

    def __init__(self):
        self._obj = Dm.CDataTable()

    def load(self, file_path: str) -> bool | int:
        """
        加载数据表文件
        :param file_path: UTF-8 编码的数据表文件路径
        :return: 加载结果(成功返回 True/0,失败返回 False/错误码)

        example:
        ```python
        dt = DmDataTable()
        dt.load("E:/dassistant/tests/123.dmd")
        print("字段总数:",dt.get_field_count())
        ```
        """
        if not isinstance(file_path, str) or not file_path.strip():
            raise ValueError("文件路径不能为空字符串")
        return self._obj.Load(file_path)

    def get_field_count(self) -> int:
        """获取字段总数"""
        return self._obj.Get_Field_Count()

    def get_record_count(self) -> int:
        """获取记录总数"""
        return self._obj.Get_Record_Count()

    def get_record_data(self, record_index: int) -> dict:
        """
        通过索引获取单条记录的完整数据
        :param record_index: 记录索引(从0开始)
        :return: 记录数据字典,键为字段名,值为字段值
        """
        return self._obj.Get_Record_Data(record_index)

    def get_field_id(self, field_name: str) -> int:
        """
        通过字段名获取字段ID
        :param field_name: UTF-8 编码的字段名
        :return: 字段ID
        """
        if not isinstance(field_name, str) or not field_name.strip():
            raise ValueError("字段名不能为空字符串")
        return self._obj.Get_Field_Id(field_name)

    def get_field_name(self, field_index: int) -> str:
        """
        通过索引获取字段名
        :param field_index: 字段索引(从0开始)
        :return: UTF-8 编码的字段名
        """
        # if not isinstance(field_index, int) or field_index < 0:
        #     raise ValueError("字段索引必须为非负整数")
        # if field_index >= self.get_field_count():
        #     raise IndexError("字段索引超出范围")
        return self._obj.Get_Field_Name(field_index)

    def get_field_display_name(self, field_index: int) -> str:
        """
        通过索引获取字段显示名
        :param field_index: 字段索引(从0开始)
        :return: UTF-8 编码的字段显示名
        """
        # if not isinstance(field_index, int) or field_index < 0:
        #     raise ValueError("字段索引必须为非负整数")
        # if field_index >= self.get_field_count():
        #     raise IndexError("字段索引超出范围")
        return self._obj.Get_Field_DisplayName(field_index)

    def get_field_type(self, field_index: int) -> int:
        """
        通过索引获取字段类型
        :param field_index: 字段索引(从0开始)
        :return: 字段类型枚举值
        """
        # if not isinstance(field_index, int) or field_index < 0:
        #     raise ValueError("字段索引必须为非负整数")
        # if field_index >= self.get_field_count():
        #     raise IndexError("字段索引超出范围")
        return self._obj.Get_Field_Type(field_index)

    def get_record_from_index(self, record_index: int) -> DmDataTableRecord:
        """
        通过索引获取原始记录对象
        :param record_index: 记录索引(从0开始)
        :return: 原始记录对象
        """
        # if not isinstance(record_index, int) or record_index < 0:
        #     raise ValueError("记录索引必须为非负整数")
        # if record_index >= self.get_record_count():
        #     raise IndexError("记录索引超出范围")
        cpp_result = self._obj.Get_Record_From_Index(record_index)
        return DmDataTableRecord._from_obj(cpp_result)

    def get_record_count_by_condition(self, field_name: str, field_value: str) -> int:
        """
        根据字段名和值筛选记录数量
        :param field_name: UTF-8 编码的字段名
        :param field_value: UTF-8 编码的字段值
        :return: 符合条件的记录数量
        """
        if not isinstance(field_name, str) or not field_name.strip():
            raise ValueError("字段名不能为空字符串")
        if not isinstance(field_value, str):
            raise ValueError("字段值必须为字符串")
        return self._obj.GetRecordCountByCondition(field_name, field_value)

    def add_record(self) -> bool | int:
        """添加一条新记录"""
        return self._obj.Add_Record()

    def save(self) -> bool | int:
        """保存数据表"""
        return self._obj.Save()

    @classmethod
    def _from_obj(cls, obj):
        """
        原生dmDataTable对象创建封装实例
        :param obj: 原生dmDataTable对象(bind11封装后)
        :return: DmDataTable实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

add_record()

添加一条新记录

Source code in dimine_python_sdk\lib\types\entity.py
940
941
942
def add_record(self) -> bool | int:
    """添加一条新记录"""
    return self._obj.Add_Record()

get_field_count()

获取字段总数

Source code in dimine_python_sdk\lib\types\entity.py
852
853
854
def get_field_count(self) -> int:
    """获取字段总数"""
    return self._obj.Get_Field_Count()

get_field_display_name(field_index)

通过索引获取字段显示名 :param field_index: 字段索引(从0开始) :return: UTF-8 编码的字段显示名

Source code in dimine_python_sdk\lib\types\entity.py
890
891
892
893
894
895
896
897
898
899
900
def get_field_display_name(self, field_index: int) -> str:
    """
    通过索引获取字段显示名
    :param field_index: 字段索引(从0开始)
    :return: UTF-8 编码的字段显示名
    """
    # if not isinstance(field_index, int) or field_index < 0:
    #     raise ValueError("字段索引必须为非负整数")
    # if field_index >= self.get_field_count():
    #     raise IndexError("字段索引超出范围")
    return self._obj.Get_Field_DisplayName(field_index)

get_field_id(field_name)

通过字段名获取字段ID :param field_name: UTF-8 编码的字段名 :return: 字段ID

Source code in dimine_python_sdk\lib\types\entity.py
868
869
870
871
872
873
874
875
876
def get_field_id(self, field_name: str) -> int:
    """
    通过字段名获取字段ID
    :param field_name: UTF-8 编码的字段名
    :return: 字段ID
    """
    if not isinstance(field_name, str) or not field_name.strip():
        raise ValueError("字段名不能为空字符串")
    return self._obj.Get_Field_Id(field_name)

get_field_name(field_index)

通过索引获取字段名 :param field_index: 字段索引(从0开始) :return: UTF-8 编码的字段名

Source code in dimine_python_sdk\lib\types\entity.py
878
879
880
881
882
883
884
885
886
887
888
def get_field_name(self, field_index: int) -> str:
    """
    通过索引获取字段名
    :param field_index: 字段索引(从0开始)
    :return: UTF-8 编码的字段名
    """
    # if not isinstance(field_index, int) or field_index < 0:
    #     raise ValueError("字段索引必须为非负整数")
    # if field_index >= self.get_field_count():
    #     raise IndexError("字段索引超出范围")
    return self._obj.Get_Field_Name(field_index)

get_field_type(field_index)

通过索引获取字段类型 :param field_index: 字段索引(从0开始) :return: 字段类型枚举值

Source code in dimine_python_sdk\lib\types\entity.py
902
903
904
905
906
907
908
909
910
911
912
def get_field_type(self, field_index: int) -> int:
    """
    通过索引获取字段类型
    :param field_index: 字段索引(从0开始)
    :return: 字段类型枚举值
    """
    # if not isinstance(field_index, int) or field_index < 0:
    #     raise ValueError("字段索引必须为非负整数")
    # if field_index >= self.get_field_count():
    #     raise IndexError("字段索引超出范围")
    return self._obj.Get_Field_Type(field_index)

get_record_count()

获取记录总数

Source code in dimine_python_sdk\lib\types\entity.py
856
857
858
def get_record_count(self) -> int:
    """获取记录总数"""
    return self._obj.Get_Record_Count()

get_record_count_by_condition(field_name, field_value)

根据字段名和值筛选记录数量 :param field_name: UTF-8 编码的字段名 :param field_value: UTF-8 编码的字段值 :return: 符合条件的记录数量

Source code in dimine_python_sdk\lib\types\entity.py
927
928
929
930
931
932
933
934
935
936
937
938
def get_record_count_by_condition(self, field_name: str, field_value: str) -> int:
    """
    根据字段名和值筛选记录数量
    :param field_name: UTF-8 编码的字段名
    :param field_value: UTF-8 编码的字段值
    :return: 符合条件的记录数量
    """
    if not isinstance(field_name, str) or not field_name.strip():
        raise ValueError("字段名不能为空字符串")
    if not isinstance(field_value, str):
        raise ValueError("字段值必须为字符串")
    return self._obj.GetRecordCountByCondition(field_name, field_value)

get_record_data(record_index)

通过索引获取单条记录的完整数据 :param record_index: 记录索引(从0开始) :return: 记录数据字典,键为字段名,值为字段值

Source code in dimine_python_sdk\lib\types\entity.py
860
861
862
863
864
865
866
def get_record_data(self, record_index: int) -> dict:
    """
    通过索引获取单条记录的完整数据
    :param record_index: 记录索引(从0开始)
    :return: 记录数据字典,键为字段名,值为字段值
    """
    return self._obj.Get_Record_Data(record_index)

get_record_from_index(record_index)

通过索引获取原始记录对象 :param record_index: 记录索引(从0开始) :return: 原始记录对象

Source code in dimine_python_sdk\lib\types\entity.py
914
915
916
917
918
919
920
921
922
923
924
925
def get_record_from_index(self, record_index: int) -> DmDataTableRecord:
    """
    通过索引获取原始记录对象
    :param record_index: 记录索引(从0开始)
    :return: 原始记录对象
    """
    # if not isinstance(record_index, int) or record_index < 0:
    #     raise ValueError("记录索引必须为非负整数")
    # if record_index >= self.get_record_count():
    #     raise IndexError("记录索引超出范围")
    cpp_result = self._obj.Get_Record_From_Index(record_index)
    return DmDataTableRecord._from_obj(cpp_result)

load(file_path)

加载数据表文件 :param file_path: UTF-8 编码的数据表文件路径 :return: 加载结果(成功返回 True/0,失败返回 False/错误码)

example:

dt = DmDataTable()
dt.load("E:/dassistant/tests/123.dmd")
print("字段总数:",dt.get_field_count())
Source code in dimine_python_sdk\lib\types\entity.py
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
def load(self, file_path: str) -> bool | int:
    """
    加载数据表文件
    :param file_path: UTF-8 编码的数据表文件路径
    :return: 加载结果(成功返回 True/0,失败返回 False/错误码)

    example:
    ```python
    dt = DmDataTable()
    dt.load("E:/dassistant/tests/123.dmd")
    print("字段总数:",dt.get_field_count())
    ```
    """
    if not isinstance(file_path, str) or not file_path.strip():
        raise ValueError("文件路径不能为空字符串")
    return self._obj.Load(file_path)

save()

保存数据表

Source code in dimine_python_sdk\lib\types\entity.py
944
945
946
def save(self) -> bool | int:
    """保存数据表"""
    return self._obj.Save()

DmDataTableRecord

数据表记录类

Source code in dimine_python_sdk\lib\types\entity.py
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
class DmDataTableRecord:
    """
    数据表记录类
    """

    # def __init__(self, record_obj: Dm.CDataTableRecord):
    #     self._obj = record_obj  # 接收底层记录对象

    @classmethod
    def _from_obj(cls, obj):
        """
        原生dmDataTableRecord对象创建封装实例
        :param obj: 原生dmDataTableRecord对象(bind11封装后)
        :return: DmDataTableRecord实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

    def as_string(self, field_name: str) -> str:
        """
        获取字段值(字符串形式)
        :param field_name: UTF-8 编码的字段名
        :return: 字段值字符串
        """
        if not isinstance(field_name, str) or not field_name.strip():
            raise ValueError("字段名不能为空字符串")
        return self._obj.asString(field_name)

    def as_double(self, field_name: str) -> float:
        """
        获取字段值(浮点形式)
        :param field_name: UTF-8 编码的字段名
        :return: 字段值浮点数
        """
        if not isinstance(field_name, str) or not field_name.strip():
            raise ValueError("字段名不能为空字符串")
        return self._obj.asDouble(field_name)

    def set_value(self, field_name: str, value: str | float) -> None:
        """
        设置字段值(支持字符串/浮点数)
        :param field_name: UTF-8 编码的字段名
        :param value: 字段值(字符串或浮点数)
        """
        if not isinstance(field_name, str) or not field_name.strip():
            raise ValueError("字段名不能为空字符串")
        if isinstance(value, str):
            self._obj.Set_Value(field_name, value)
        elif isinstance(value, (int, float)):
            self._obj.Set_Value(field_name, float(value))
        else:
            raise TypeError("字段值仅支持字符串或数字类型")

as_double(field_name)

获取字段值(浮点形式) :param field_name: UTF-8 编码的字段名 :return: 字段值浮点数

Source code in dimine_python_sdk\lib\types\entity.py
801
802
803
804
805
806
807
808
809
def as_double(self, field_name: str) -> float:
    """
    获取字段值(浮点形式)
    :param field_name: UTF-8 编码的字段名
    :return: 字段值浮点数
    """
    if not isinstance(field_name, str) or not field_name.strip():
        raise ValueError("字段名不能为空字符串")
    return self._obj.asDouble(field_name)

as_string(field_name)

获取字段值(字符串形式) :param field_name: UTF-8 编码的字段名 :return: 字段值字符串

Source code in dimine_python_sdk\lib\types\entity.py
791
792
793
794
795
796
797
798
799
def as_string(self, field_name: str) -> str:
    """
    获取字段值(字符串形式)
    :param field_name: UTF-8 编码的字段名
    :return: 字段值字符串
    """
    if not isinstance(field_name, str) or not field_name.strip():
        raise ValueError("字段名不能为空字符串")
    return self._obj.asString(field_name)

set_value(field_name, value)

设置字段值(支持字符串/浮点数) :param field_name: UTF-8 编码的字段名 :param value: 字段值(字符串或浮点数)

Source code in dimine_python_sdk\lib\types\entity.py
811
812
813
814
815
816
817
818
819
820
821
822
823
824
def set_value(self, field_name: str, value: str | float) -> None:
    """
    设置字段值(支持字符串/浮点数)
    :param field_name: UTF-8 编码的字段名
    :param value: 字段值(字符串或浮点数)
    """
    if not isinstance(field_name, str) or not field_name.strip():
        raise ValueError("字段名不能为空字符串")
    if isinstance(value, str):
        self._obj.Set_Value(field_name, value)
    elif isinstance(value, (int, float)):
        self._obj.Set_Value(field_name, float(value))
    else:
        raise TypeError("字段值仅支持字符串或数字类型")

DmDbDatabase

几何数据库

Source code in dimine_python_sdk\lib\types\entity.py
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
class DmDbDatabase:
    """
    几何数据库
    """

    def __init__(self):
        # 初始化源扩展的核心对象,作为底层操作入口
        self._db = Dm.dmDbDatabase()

    def load(self, file_path: str) -> bool | int:
        """
        加载本地数据库文件(底层调用源Load接口)
        :param file_path: 数据库文件路径(UTF-8编码,底层已处理编码转换)
        :return: 加载结果,成功返回True/0,失败返回False/错误码

        example:
        ```python
        dmf = DmDbDatabase()
        db = dmf.load('E:/dassistant/tests/123.dmf')
        print(db)
        ```
        """
        if not isinstance(file_path, str) or not file_path.strip():
            raise ValueError("文件路径不能为空字符串")
        return self._db.Load(file_path)

    def get_layers_count(self) -> int:
        """
        获取数据库图层总数(底层调用源GetLayersCount接口)
        :return: 非负整数,图层总数量

        example:
        ```python
        dmf = DmDbDatabase()
        db = dmf.load('E:/dassistant/tests/123.dmf')
        print("获取图层数量:",dmf.get_layers_count())
        ```
        """
        return self._db.GetLayersCount()

    def get_layer_by_index(self, layer_index: int) -> DmDbLayer | None:
        """
        通过索引获取图层对象(底层调用源GetLayerFromIndex接口)
        :param layer_index: 图层索引,从0开始
        :return: 图层对象,索引无效时返回None
        """
        if not isinstance(layer_index, int) or layer_index < 0:
            raise ValueError("图层索引必须为非负整数")
        cpp_result = self._db.GetLayerFromIndex(layer_index)
        return DmDbLayer._from_obj(cpp_result)

    def set_file_name(self, file_path: str) -> None:
        """
        设置数据库文件路径(底层调用源SetFileName接口)
        :param file_path: 数据库文件路径(UTF-8编码)
        """
        if not isinstance(file_path, str) or not file_path.strip():
            raise ValueError("文件路径不能为空字符串")
        self._db.SetFileName(file_path)

    def insert_layer(self, layer_name: str) -> DmDbLayer:
        """
        插入新图层(底层调用源InsertLayer接口)
        :param layer_name: 图层名称(UTF-8编码)
        :return: 新创建的图层对象

        example:
        ```python
        dmf = DmDbDatabase()
        db = dmf.load('E:/dassistant/tests/123.dmf')
        layer = dmf.insert_layer("新图层")
        print("插入新图层:",layer)
        ```
        """
        if not isinstance(layer_name, str) or not layer_name.strip():
            raise ValueError("图层名称不能为空字符串")
        cpp_result = self._db.InsertLayer(layer_name.strip())
        return DmDbLayer._from_obj(cpp_result)

    def save(self, file_path: str | None = None) -> bool | int:
        """
        保存数据库(底层调用源Save重载接口,自动适配无参/有参)
        :param file_path: 可选保存路径,为None时保存到当前路径
        :return: 保存结果,成功返回True/0,失败返回False/错误码

        example:
        ```python
        dmf = DmDbDatabase()
        db = dmf.load('E:/dassistant/tests/123.dmf')
        layer = dmf.insert_layer("新图层")
        print("插入新图层:",layer)
        dmf.save("E:/dassistant/tests/123_1.dmf")
        ```
        """
        if file_path is None:
            return self._db.Save()
        if not isinstance(file_path, str) or not file_path.strip():
            raise ValueError("保存路径不能为空字符串")
        return self._db.Save(file_path)

    def switch_to_local_storage(self) -> None:
        """切换到本地存储模式(底层调用源SetToLocalStorage接口)"""
        self._db.SetToLocalStorage()

    def get_active_layer(self) -> DmDbLayer | None:
        """
        获取当前激活图层(底层调用源GetActiveLayer接口)
        :return: 激活图层对象,无激活图层时返回None

        example:
        ```python
        dmf = DmDbDatabase()
        db = dmf.load('E:/dassistant/tests/123.dmf')
        layer = dmf.get_active_layer()
        print("当前活动图层:",layer)
        ```
        """
        cpp_result = self._db.GetActiveLayer()
        return DmDbLayer._from_obj(cpp_result)

    @staticmethod
    def create_local_db() -> "DmDbDatabase":
        """
        创建本地数据库(底层调用源CreateLocalDB静态接口)
        :return: 新创建的数据库对象
        """
        cpp_db = Dm.dmDbDatabase.CreateLocalDB()
        return DmDbDatabase._from_obj(cpp_db)

    def close_polyline(self) -> bool | int:
        """
        闭合多段线(底层调用源ClosePolyline接口)
        :return: 操作结果
        """
        return self._db.ClosePolyline()

    def set_color(self, red: int, green: int, blue: int) -> None:
        """
        设置颜色(底层调用源SetColor接口)
        :param red: 红色通道值(0-255)
        :param green: 绿色通道值(0-255)
        :param blue: 蓝色通道值(0-255)
        """
        if not (0 <= red <= 255) or not (0 <= green <= 255) or not (0 <= blue <= 255):
            raise ValueError("颜色值必须在0-255之间")
        self._db.SetColor(red, green, blue)

    def add_property(self, property_name: str, property_type: str) -> tuple[bool, str]:
        """
        添加属性(底层调用源AddProperty接口)
        :param property_name: 属性名称(UTF-8编码)
        :param property_type: 属性类型(UTF-8编码)
        :return: 操作结果(是否成功,提示信息)
        """
        if not isinstance(property_name, str) or not property_name.strip():
            raise ValueError("属性名称不能为空")
        if not isinstance(property_type, str):
            raise ValueError("属性类型必须为字符串")
        return self._db.AddProperty(property_name, property_type)

    @classmethod
    def _from_obj(cls, obj):
        """
        原生dmDbDatabase对象创建封装实例
        :param obj: 原生dmDbDatabase对象(bind11封装后)
        :return: DmDbDatabase实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

add_property(property_name, property_type)

添加属性(底层调用源AddProperty接口) :param property_name: 属性名称(UTF-8编码) :param property_type: 属性类型(UTF-8编码) :return: 操作结果(是否成功,提示信息)

Source code in dimine_python_sdk\lib\types\entity.py
747
748
749
750
751
752
753
754
755
756
757
758
def add_property(self, property_name: str, property_type: str) -> tuple[bool, str]:
    """
    添加属性(底层调用源AddProperty接口)
    :param property_name: 属性名称(UTF-8编码)
    :param property_type: 属性类型(UTF-8编码)
    :return: 操作结果(是否成功,提示信息)
    """
    if not isinstance(property_name, str) or not property_name.strip():
        raise ValueError("属性名称不能为空")
    if not isinstance(property_type, str):
        raise ValueError("属性类型必须为字符串")
    return self._db.AddProperty(property_name, property_type)

close_polyline()

闭合多段线(底层调用源ClosePolyline接口) :return: 操作结果

Source code in dimine_python_sdk\lib\types\entity.py
729
730
731
732
733
734
def close_polyline(self) -> bool | int:
    """
    闭合多段线(底层调用源ClosePolyline接口)
    :return: 操作结果
    """
    return self._db.ClosePolyline()

create_local_db() staticmethod

创建本地数据库(底层调用源CreateLocalDB静态接口) :return: 新创建的数据库对象

Source code in dimine_python_sdk\lib\types\entity.py
720
721
722
723
724
725
726
727
@staticmethod
def create_local_db() -> "DmDbDatabase":
    """
    创建本地数据库(底层调用源CreateLocalDB静态接口)
    :return: 新创建的数据库对象
    """
    cpp_db = Dm.dmDbDatabase.CreateLocalDB()
    return DmDbDatabase._from_obj(cpp_db)

get_active_layer()

获取当前激活图层(底层调用源GetActiveLayer接口) :return: 激活图层对象,无激活图层时返回None

example:

dmf = DmDbDatabase()
db = dmf.load('E:/dassistant/tests/123.dmf')
layer = dmf.get_active_layer()
print("当前活动图层:",layer)
Source code in dimine_python_sdk\lib\types\entity.py
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
def get_active_layer(self) -> DmDbLayer | None:
    """
    获取当前激活图层(底层调用源GetActiveLayer接口)
    :return: 激活图层对象,无激活图层时返回None

    example:
    ```python
    dmf = DmDbDatabase()
    db = dmf.load('E:/dassistant/tests/123.dmf')
    layer = dmf.get_active_layer()
    print("当前活动图层:",layer)
    ```
    """
    cpp_result = self._db.GetActiveLayer()
    return DmDbLayer._from_obj(cpp_result)

get_layer_by_index(layer_index)

通过索引获取图层对象(底层调用源GetLayerFromIndex接口) :param layer_index: 图层索引,从0开始 :return: 图层对象,索引无效时返回None

Source code in dimine_python_sdk\lib\types\entity.py
640
641
642
643
644
645
646
647
648
649
def get_layer_by_index(self, layer_index: int) -> DmDbLayer | None:
    """
    通过索引获取图层对象(底层调用源GetLayerFromIndex接口)
    :param layer_index: 图层索引,从0开始
    :return: 图层对象,索引无效时返回None
    """
    if not isinstance(layer_index, int) or layer_index < 0:
        raise ValueError("图层索引必须为非负整数")
    cpp_result = self._db.GetLayerFromIndex(layer_index)
    return DmDbLayer._from_obj(cpp_result)

get_layers_count()

获取数据库图层总数(底层调用源GetLayersCount接口) :return: 非负整数,图层总数量

example:

dmf = DmDbDatabase()
db = dmf.load('E:/dassistant/tests/123.dmf')
print("获取图层数量:",dmf.get_layers_count())
Source code in dimine_python_sdk\lib\types\entity.py
626
627
628
629
630
631
632
633
634
635
636
637
638
def get_layers_count(self) -> int:
    """
    获取数据库图层总数(底层调用源GetLayersCount接口)
    :return: 非负整数,图层总数量

    example:
    ```python
    dmf = DmDbDatabase()
    db = dmf.load('E:/dassistant/tests/123.dmf')
    print("获取图层数量:",dmf.get_layers_count())
    ```
    """
    return self._db.GetLayersCount()

insert_layer(layer_name)

插入新图层(底层调用源InsertLayer接口) :param layer_name: 图层名称(UTF-8编码) :return: 新创建的图层对象

example:

dmf = DmDbDatabase()
db = dmf.load('E:/dassistant/tests/123.dmf')
layer = dmf.insert_layer("新图层")
print("插入新图层:",layer)
Source code in dimine_python_sdk\lib\types\entity.py
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
def insert_layer(self, layer_name: str) -> DmDbLayer:
    """
    插入新图层(底层调用源InsertLayer接口)
    :param layer_name: 图层名称(UTF-8编码)
    :return: 新创建的图层对象

    example:
    ```python
    dmf = DmDbDatabase()
    db = dmf.load('E:/dassistant/tests/123.dmf')
    layer = dmf.insert_layer("新图层")
    print("插入新图层:",layer)
    ```
    """
    if not isinstance(layer_name, str) or not layer_name.strip():
        raise ValueError("图层名称不能为空字符串")
    cpp_result = self._db.InsertLayer(layer_name.strip())
    return DmDbLayer._from_obj(cpp_result)

load(file_path)

加载本地数据库文件(底层调用源Load接口) :param file_path: 数据库文件路径(UTF-8编码,底层已处理编码转换) :return: 加载结果,成功返回True/0,失败返回False/错误码

example:

dmf = DmDbDatabase()
db = dmf.load('E:/dassistant/tests/123.dmf')
print(db)
Source code in dimine_python_sdk\lib\types\entity.py
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
def load(self, file_path: str) -> bool | int:
    """
    加载本地数据库文件(底层调用源Load接口)
    :param file_path: 数据库文件路径(UTF-8编码,底层已处理编码转换)
    :return: 加载结果,成功返回True/0,失败返回False/错误码

    example:
    ```python
    dmf = DmDbDatabase()
    db = dmf.load('E:/dassistant/tests/123.dmf')
    print(db)
    ```
    """
    if not isinstance(file_path, str) or not file_path.strip():
        raise ValueError("文件路径不能为空字符串")
    return self._db.Load(file_path)

save(file_path=None)

保存数据库(底层调用源Save重载接口,自动适配无参/有参) :param file_path: 可选保存路径,为None时保存到当前路径 :return: 保存结果,成功返回True/0,失败返回False/错误码

example:

dmf = DmDbDatabase()
db = dmf.load('E:/dassistant/tests/123.dmf')
layer = dmf.insert_layer("新图层")
print("插入新图层:",layer)
dmf.save("E:/dassistant/tests/123_1.dmf")
Source code in dimine_python_sdk\lib\types\entity.py
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
def save(self, file_path: str | None = None) -> bool | int:
    """
    保存数据库(底层调用源Save重载接口,自动适配无参/有参)
    :param file_path: 可选保存路径,为None时保存到当前路径
    :return: 保存结果,成功返回True/0,失败返回False/错误码

    example:
    ```python
    dmf = DmDbDatabase()
    db = dmf.load('E:/dassistant/tests/123.dmf')
    layer = dmf.insert_layer("新图层")
    print("插入新图层:",layer)
    dmf.save("E:/dassistant/tests/123_1.dmf")
    ```
    """
    if file_path is None:
        return self._db.Save()
    if not isinstance(file_path, str) or not file_path.strip():
        raise ValueError("保存路径不能为空字符串")
    return self._db.Save(file_path)

set_color(red, green, blue)

设置颜色(底层调用源SetColor接口) :param red: 红色通道值(0-255) :param green: 绿色通道值(0-255) :param blue: 蓝色通道值(0-255)

Source code in dimine_python_sdk\lib\types\entity.py
736
737
738
739
740
741
742
743
744
745
def set_color(self, red: int, green: int, blue: int) -> None:
    """
    设置颜色(底层调用源SetColor接口)
    :param red: 红色通道值(0-255)
    :param green: 绿色通道值(0-255)
    :param blue: 蓝色通道值(0-255)
    """
    if not (0 <= red <= 255) or not (0 <= green <= 255) or not (0 <= blue <= 255):
        raise ValueError("颜色值必须在0-255之间")
    self._db.SetColor(red, green, blue)

set_file_name(file_path)

设置数据库文件路径(底层调用源SetFileName接口) :param file_path: 数据库文件路径(UTF-8编码)

Source code in dimine_python_sdk\lib\types\entity.py
651
652
653
654
655
656
657
658
def set_file_name(self, file_path: str) -> None:
    """
    设置数据库文件路径(底层调用源SetFileName接口)
    :param file_path: 数据库文件路径(UTF-8编码)
    """
    if not isinstance(file_path, str) or not file_path.strip():
        raise ValueError("文件路径不能为空字符串")
    self._db.SetFileName(file_path)

switch_to_local_storage()

切换到本地存储模式(底层调用源SetToLocalStorage接口)

Source code in dimine_python_sdk\lib\types\entity.py
700
701
702
def switch_to_local_storage(self) -> None:
    """切换到本地存储模式(底层调用源SetToLocalStorage接口)"""
    self._db.SetToLocalStorage()

DmDbEntity

所有实体对象都继承自该类,包括获取实体类型函数GetType、 将三维实体转换到dmPolyData对象函数ToPolyData、 将对象转换为三维实体对象函数ConvertToShell、 将对象转换为三维多段线对象函数ConvertToPolyline、 将对象转换为直线对象函数ConvertToLine、 将对象转换为点对象函数ConvertToPoint、 设置实体颜色函数SetColor、 获取实体类型名称函数GetEntityTypeName、 获取实体名称函数GetEntityName等

example:

dmf = DmDbDatabase()
db = dmf.load('E:/dassistant/tests/123.dmf')
print("获取图层数量:",dmf.get_layers_count())
act_layer = dmf.get_active_layer()

layerCount = dmf.get_layers_count()
for i in range(layerCount):
    layer = dmf.get_layer_by_index(i)
    if layer is None:
        continue

    print("图层实体数量:",layer.get_entities_count())

    layer.start_query_entity()
    entity = layer.open_next_entity()
    while entity is not None:
        nType = entity.get_type()
        #print("实体类型:",nType)
        if nType == EntityType.ETT_POLYLINE:
            print("实体类型名称:", entity.get_entity_type_name())
            polydata = entity.to_poly_data()
            print("获取多边形点集:",polydata.get_dm_points())
            print("获取多边形包围盒:",polydata.get_bounds())
        elif nType == EntityType.ETT_POINT:
            print("实体类型名称:", entity.get_entity_type_name())
            point = entity.convert_to_point().get_graph_data()
            print(type(point))
            print("获取点数据:",point)
        elif nType == EntityType.ETT_LINE:
            print("实体类型名称:", entity.get_entity_type_name())
            line = entity.convert_to_line()
            print(type(line))
            print("获取线数据:",line)
            entity.set_color(255,0,0)
        entity = layer.open_next_entity()
Source code in dimine_python_sdk\lib\types\entity.py
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
class DmDbEntity:
    """所有实体对象都继承自该类,包括获取实体类型函数GetType、
    将三维实体转换到dmPolyData对象函数ToPolyData、
    将对象转换为三维实体对象函数ConvertToShell、
    将对象转换为三维多段线对象函数ConvertToPolyline、
    将对象转换为直线对象函数ConvertToLine、
    将对象转换为点对象函数ConvertToPoint、
    设置实体颜色函数SetColor、
    获取实体类型名称函数GetEntityTypeName、
    获取实体名称函数GetEntityName等

    example:
    ```python
    dmf = DmDbDatabase()
    db = dmf.load('E:/dassistant/tests/123.dmf')
    print("获取图层数量:",dmf.get_layers_count())
    act_layer = dmf.get_active_layer()

    layerCount = dmf.get_layers_count()
    for i in range(layerCount):
        layer = dmf.get_layer_by_index(i)
        if layer is None:
            continue

        print("图层实体数量:",layer.get_entities_count())

        layer.start_query_entity()
        entity = layer.open_next_entity()
        while entity is not None:
            nType = entity.get_type()
            #print("实体类型:",nType)
            if nType == EntityType.ETT_POLYLINE:
                print("实体类型名称:", entity.get_entity_type_name())
                polydata = entity.to_poly_data()
                print("获取多边形点集:",polydata.get_dm_points())
                print("获取多边形包围盒:",polydata.get_bounds())
            elif nType == EntityType.ETT_POINT:
                print("实体类型名称:", entity.get_entity_type_name())
                point = entity.convert_to_point().get_graph_data()
                print(type(point))
                print("获取点数据:",point)
            elif nType == EntityType.ETT_LINE:
                print("实体类型名称:", entity.get_entity_type_name())
                line = entity.convert_to_line()
                print(type(line))
                print("获取线数据:",line)
                entity.set_color(255,0,0)
            entity = layer.open_next_entity()
    ```
    """

    # def __init__(self):
    #     self._obj = None


    @classmethod
    def _from_obj(cls, obj):
        """
        原生DmDbEntity对象创建封装实例
        :param obj: 原生DmDbEntity对象(bind11封装后)
        :return: DmDbEntity实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

    def get_type(self) -> int:
        """
        获取实体类型编码
        :return: 实体类型的整数编码
        """
        return self._obj.GetType()

    def to_poly_data(self) -> DmPolyData:
        """
        将实体转换为多边形数据
        :return: 转换后的DmPolyData实例(需提前实现该类及_from_obj方法)
        """
        cpp_result = self._obj.ToPolyData()
        return DmPolyData._from_obj(cpp_result)

    def convert_to_shell(self) -> DmDbShell:
        """
        将实体转换为Shell对象
        :return: 转换后的DmDbShell实例
        """
        cpp_result = self._obj.ConvertToShell()
        return DmDbShell._from_obj(cpp_result)

    def convert_to_polyline(self) -> DmDbPolyline:
        """
        将实体转换为多段线对象
        :return: 转换后的DmDbPolyline实例
        """
        cpp_result = self._obj.ConvertToPolyline()
        return DmDbPolyline._from_obj(cpp_result)

    def convert_to_line(self) -> DmDbLine:
        """
        将实体转换为线对象
        :return: 转换后的DmDbLine实例
        """
        cpp_result = self._obj.ConvertToLine()
        return DmDbLine._from_obj(cpp_result)

    def convert_to_point(self) -> DmDbPoint:
        """
        将实体转换为点对象
        :return: 转换后的DmDbPoint实例
        """
        cpp_result = self._obj.ConvertToPoint()
        return DmDbPoint._from_obj(cpp_result)

    def set_color(self, red: int, green: int, blue: int) -> None:
        """
        设置实体颜色
        :param red: 红色分量(0-255)
        :param green: 绿色分量(0-255)
        :param blue: 蓝色分量(0-255)

        example:
        ```python
        entity = DmDbEntity()
        entity.set_color(255, 0, 0)
        ```
        """
        self._obj.SetColor(red, green, blue)

    def get_entity_type_name(self) -> str:
        """
        获取实体类型名称(UTF-8编码)
        :return: 实体类型名称字符串

        example:
        ```python
        entity = DmDbEntity()
        entity_type_name = entity.get_entity_type_name()
        ```
        """
        return self._obj.GetEntityTypeName()

    def get_entity_name(self) -> str:
        """
        获取实体名称(UTF-8编码)
        :return: 实体名称字符串

        example:
        ```python
        entity = DmDbEntity()
        entity_name = entity.get_entity_name()
        ```
        """
        return self._obj.GetEntityName()

convert_to_line()

将实体转换为线对象 :return: 转换后的DmDbLine实例

Source code in dimine_python_sdk\lib\types\entity.py
429
430
431
432
433
434
435
def convert_to_line(self) -> DmDbLine:
    """
    将实体转换为线对象
    :return: 转换后的DmDbLine实例
    """
    cpp_result = self._obj.ConvertToLine()
    return DmDbLine._from_obj(cpp_result)

convert_to_point()

将实体转换为点对象 :return: 转换后的DmDbPoint实例

Source code in dimine_python_sdk\lib\types\entity.py
437
438
439
440
441
442
443
def convert_to_point(self) -> DmDbPoint:
    """
    将实体转换为点对象
    :return: 转换后的DmDbPoint实例
    """
    cpp_result = self._obj.ConvertToPoint()
    return DmDbPoint._from_obj(cpp_result)

convert_to_polyline()

将实体转换为多段线对象 :return: 转换后的DmDbPolyline实例

Source code in dimine_python_sdk\lib\types\entity.py
421
422
423
424
425
426
427
def convert_to_polyline(self) -> DmDbPolyline:
    """
    将实体转换为多段线对象
    :return: 转换后的DmDbPolyline实例
    """
    cpp_result = self._obj.ConvertToPolyline()
    return DmDbPolyline._from_obj(cpp_result)

convert_to_shell()

将实体转换为Shell对象 :return: 转换后的DmDbShell实例

Source code in dimine_python_sdk\lib\types\entity.py
413
414
415
416
417
418
419
def convert_to_shell(self) -> DmDbShell:
    """
    将实体转换为Shell对象
    :return: 转换后的DmDbShell实例
    """
    cpp_result = self._obj.ConvertToShell()
    return DmDbShell._from_obj(cpp_result)

get_entity_name()

获取实体名称(UTF-8编码) :return: 实体名称字符串

example:

entity = DmDbEntity()
entity_name = entity.get_entity_name()
Source code in dimine_python_sdk\lib\types\entity.py
473
474
475
476
477
478
479
480
481
482
483
484
def get_entity_name(self) -> str:
    """
    获取实体名称(UTF-8编码)
    :return: 实体名称字符串

    example:
    ```python
    entity = DmDbEntity()
    entity_name = entity.get_entity_name()
    ```
    """
    return self._obj.GetEntityName()

get_entity_type_name()

获取实体类型名称(UTF-8编码) :return: 实体类型名称字符串

example:

entity = DmDbEntity()
entity_type_name = entity.get_entity_type_name()
Source code in dimine_python_sdk\lib\types\entity.py
460
461
462
463
464
465
466
467
468
469
470
471
def get_entity_type_name(self) -> str:
    """
    获取实体类型名称(UTF-8编码)
    :return: 实体类型名称字符串

    example:
    ```python
    entity = DmDbEntity()
    entity_type_name = entity.get_entity_type_name()
    ```
    """
    return self._obj.GetEntityTypeName()

get_type()

获取实体类型编码 :return: 实体类型的整数编码

Source code in dimine_python_sdk\lib\types\entity.py
398
399
400
401
402
403
def get_type(self) -> int:
    """
    获取实体类型编码
    :return: 实体类型的整数编码
    """
    return self._obj.GetType()

set_color(red, green, blue)

设置实体颜色 :param red: 红色分量(0-255) :param green: 绿色分量(0-255) :param blue: 蓝色分量(0-255)

example:

entity = DmDbEntity()
entity.set_color(255, 0, 0)
Source code in dimine_python_sdk\lib\types\entity.py
445
446
447
448
449
450
451
452
453
454
455
456
457
458
def set_color(self, red: int, green: int, blue: int) -> None:
    """
    设置实体颜色
    :param red: 红色分量(0-255)
    :param green: 绿色分量(0-255)
    :param blue: 蓝色分量(0-255)

    example:
    ```python
    entity = DmDbEntity()
    entity.set_color(255, 0, 0)
    ```
    """
    self._obj.SetColor(red, green, blue)

to_poly_data()

将实体转换为多边形数据 :return: 转换后的DmPolyData实例(需提前实现该类及_from_obj方法)

Source code in dimine_python_sdk\lib\types\entity.py
405
406
407
408
409
410
411
def to_poly_data(self) -> DmPolyData:
    """
    将实体转换为多边形数据
    :return: 转换后的DmPolyData实例(需提前实现该类及_from_obj方法)
    """
    cpp_result = self._obj.ToPolyData()
    return DmPolyData._from_obj(cpp_result)

DmDbLayer

Source code in dimine_python_sdk\lib\types\entity.py
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
class DmDbLayer:
    def __init__(self):
        self._obj = Dm.dmDbLayer()

    def start_query_entity(self) -> None:
        """
        开始查询实体

        example:
        ```python
        dmf = DmDbDatabase()
        db = dmf.load('E:/dassistant/tests/123.dmf')
        print("获取图层数量:",dmf.get_layers_count())
        act_layer = dmf.get_active_layer()

        layerCount = dmf.get_layers_count()
        for i in range(layerCount):
            layer = dmf.get_layer_by_index(i)
            if layer is None:
                continue

            print("图层实体数量:",layer.get_entities_count())

            layer.start_query_entity()
            entity = layer.open_next_entity()
            while entity is not None:
                nType = entity.get_type()
                #print("实体类型:",nType)
                if nType == EntityType.ETT_POLYLINE:
                    ···
                entity = layer.open_next_entity()
        ```
        """
        self._obj.StartQueryEntity()

    def get_entities_count(self) -> int:
        """获取实体数量"""
        return self._obj.GetEntitiesCount()

    def open_next_entity(self) -> Optional[DmDbEntity]:
        """打开下一个实体,返回封装后的实体对象,无实体时返回 None"""
        raw_entity = self._obj.OpenNextEntity()
        if raw_entity:
            return DmDbEntity._from_obj(raw_entity)
        return None

    def insert_entity(self, entity: Union[DmDbEntity, DmDbPolyline]) -> None:
        """插入实体,支持 DmDbEntity 和 dmDbPolyline 类型"""
        self._obj.InsertEntity(entity._obj)

    def insert_polyline(self, points: List[DmDPoint]) -> DmDbEntity:
        """插入多段线,返回封装后的实体对象"""
        cpp_points = [p._obj for p in points]
        raw_entity = self._obj.InsertPolyline(cpp_points)
        return DmDbEntity._from_obj(raw_entity)

    def insert_line(self, start: DmDPoint, end: DmDPoint) -> DmDbEntity:
        """插入直线,返回封装后的实体对象"""
        raw_entity = self._obj.InsertLine(start._obj, end._obj)
        return DmDbEntity._from_obj(raw_entity)

    def set_work_plane_entity(self, work_plane: DmDbWorkPlane) -> None:
        """设置工作平面实体"""
        self._obj.SetWorkPlaneEntity(work_plane._obj)

    @classmethod
    def _from_obj(cls, obj):
        """
        原生dmDbLayer对象创建封装实例
        :param obj: 原生dmDbLayer对象(bind11封装后)
        :return: DmDbLayer实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

get_entities_count()

获取实体数量

Source code in dimine_python_sdk\lib\types\entity.py
558
559
560
def get_entities_count(self) -> int:
    """获取实体数量"""
    return self._obj.GetEntitiesCount()

insert_entity(entity)

插入实体,支持 DmDbEntity 和 dmDbPolyline 类型

Source code in dimine_python_sdk\lib\types\entity.py
569
570
571
def insert_entity(self, entity: Union[DmDbEntity, DmDbPolyline]) -> None:
    """插入实体,支持 DmDbEntity 和 dmDbPolyline 类型"""
    self._obj.InsertEntity(entity._obj)

insert_line(start, end)

插入直线,返回封装后的实体对象

Source code in dimine_python_sdk\lib\types\entity.py
579
580
581
582
def insert_line(self, start: DmDPoint, end: DmDPoint) -> DmDbEntity:
    """插入直线,返回封装后的实体对象"""
    raw_entity = self._obj.InsertLine(start._obj, end._obj)
    return DmDbEntity._from_obj(raw_entity)

insert_polyline(points)

插入多段线,返回封装后的实体对象

Source code in dimine_python_sdk\lib\types\entity.py
573
574
575
576
577
def insert_polyline(self, points: List[DmDPoint]) -> DmDbEntity:
    """插入多段线,返回封装后的实体对象"""
    cpp_points = [p._obj for p in points]
    raw_entity = self._obj.InsertPolyline(cpp_points)
    return DmDbEntity._from_obj(raw_entity)

open_next_entity()

打开下一个实体,返回封装后的实体对象,无实体时返回 None

Source code in dimine_python_sdk\lib\types\entity.py
562
563
564
565
566
567
def open_next_entity(self) -> Optional[DmDbEntity]:
    """打开下一个实体,返回封装后的实体对象,无实体时返回 None"""
    raw_entity = self._obj.OpenNextEntity()
    if raw_entity:
        return DmDbEntity._from_obj(raw_entity)
    return None

set_work_plane_entity(work_plane)

设置工作平面实体

Source code in dimine_python_sdk\lib\types\entity.py
584
585
586
def set_work_plane_entity(self, work_plane: DmDbWorkPlane) -> None:
    """设置工作平面实体"""
    self._obj.SetWorkPlaneEntity(work_plane._obj)

start_query_entity()

开始查询实体

example:

dmf = DmDbDatabase()
db = dmf.load('E:/dassistant/tests/123.dmf')
print("获取图层数量:",dmf.get_layers_count())
act_layer = dmf.get_active_layer()

layerCount = dmf.get_layers_count()
for i in range(layerCount):
    layer = dmf.get_layer_by_index(i)
    if layer is None:
        continue

    print("图层实体数量:",layer.get_entities_count())

    layer.start_query_entity()
    entity = layer.open_next_entity()
    while entity is not None:
        nType = entity.get_type()
        #print("实体类型:",nType)
        if nType == EntityType.ETT_POLYLINE:
            ···
        entity = layer.open_next_entity()
Source code in dimine_python_sdk\lib\types\entity.py
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
def start_query_entity(self) -> None:
    """
    开始查询实体

    example:
    ```python
    dmf = DmDbDatabase()
    db = dmf.load('E:/dassistant/tests/123.dmf')
    print("获取图层数量:",dmf.get_layers_count())
    act_layer = dmf.get_active_layer()

    layerCount = dmf.get_layers_count()
    for i in range(layerCount):
        layer = dmf.get_layer_by_index(i)
        if layer is None:
            continue

        print("图层实体数量:",layer.get_entities_count())

        layer.start_query_entity()
        entity = layer.open_next_entity()
        while entity is not None:
            nType = entity.get_type()
            #print("实体类型:",nType)
            if nType == EntityType.ETT_POLYLINE:
                ···
            entity = layer.open_next_entity()
    ```
    """
    self._obj.StartQueryEntity()

DmDbShell

shell类

Source code in dimine_python_sdk\lib\types\entity.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class DmDbShell:
    """shell类"""
    def __init__(self):
        """构造函数,初始化Shell对象"""
        self._obj = Dm.dmDbShell()

    @classmethod
    def _from_obj(cls, obj):
        """
        原生对象创建封装实例
        :param obj: 原生dmDbShell对象
        :return: DmDbShell实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

__init__()

构造函数,初始化Shell对象

Source code in dimine_python_sdk\lib\types\entity.py
61
62
63
def __init__(self):
    """构造函数,初始化Shell对象"""
    self._obj = Dm.dmDbShell()

DmDbWorkPlane

Source code in dimine_python_sdk\lib\types\entity.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
class DmDbWorkPlane:
    def __init__(self):
        """
        构造工作平面
        """
        self._obj = Dm.dmDbWorkPlane()

    def set_normal(self, normal: DmDPoint) -> None:
        """设置法向量"""
        self._obj.SetNormal(normal._obj)

    def set_origin(self, origin: DmDPoint) -> None:
        """设置原点"""
        self._obj.SetOrigin(origin._obj)

    def set_x_axis(self, x_axis: DmDPoint) -> None:
        """设置X轴方向"""
        self._obj.SetXAxis(x_axis._obj)

    def set_y_axis(self, y_axis: DmDPoint) -> None:
        """设置Y轴方向"""
        self._obj.SetYAxis(y_axis._obj)

    @classmethod
    def _from_obj(cls, obj):
        """
        原生dmDbWorkPlane对象创建封装实例
        :param obj: 原生dmDbWorkPlane对象(bind11封装后)
        :return: DmDbWorkPlane实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

__init__()

构造工作平面

Source code in dimine_python_sdk\lib\types\entity.py
489
490
491
492
493
def __init__(self):
    """
    构造工作平面
    """
    self._obj = Dm.dmDbWorkPlane()

set_normal(normal)

设置法向量

Source code in dimine_python_sdk\lib\types\entity.py
495
496
497
def set_normal(self, normal: DmDPoint) -> None:
    """设置法向量"""
    self._obj.SetNormal(normal._obj)

set_origin(origin)

设置原点

Source code in dimine_python_sdk\lib\types\entity.py
499
500
501
def set_origin(self, origin: DmDPoint) -> None:
    """设置原点"""
    self._obj.SetOrigin(origin._obj)

set_x_axis(x_axis)

设置X轴方向

Source code in dimine_python_sdk\lib\types\entity.py
503
504
505
def set_x_axis(self, x_axis: DmDPoint) -> None:
    """设置X轴方向"""
    self._obj.SetXAxis(x_axis._obj)

set_y_axis(y_axis)

设置Y轴方向

Source code in dimine_python_sdk\lib\types\entity.py
507
508
509
def set_y_axis(self, y_axis: DmDPoint) -> None:
    """设置Y轴方向"""
    self._obj.SetYAxis(y_axis._obj)

DmPolyData

多边形数据类

Source code in dimine_python_sdk\lib\types\entity.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
class DmPolyData:
    """多边形数据类"""

    def __init__(self):
        """
        构造函数:初始化多边形数据对象
        :return: None
        """
        self._obj = Dm.dmPolyData()

    # ---------------------- 基础属性获取 ----------------------
    def get_data_type(self) -> int:
        """
        获取多边形数据类型
        :return: 数据类型编码(整数)

        example:
        ```python
        poly_data = DmPolyData()
        data_type = poly_data.get_data_type()
        ```
        """
        return self._obj.GetDataType()

    def get_number_of_cells(self) -> int:
        """
        获取单元格数量
        :return: 单元格数量(整数)

        example:
        ```python
        poly_data = DmPolyData()
        num_cells = poly_data.get_number_of_cells()
        ```
        """
        return self._obj.GetNumberOfCells()

    def get_number_of_verts(self) -> int:
        """
        获取顶点数量
        :return: 顶点数量(整数)

        example:
        ```python
        poly_data = DmPolyData()
        num_verts = poly_data.get_number_of_verts()
        ```
        """
        return self._obj.GetNumberOfVerts()

    def get_number_of_lines(self) -> int:
        """
        获取线段数量
        :return: 线段数量(整数)

        example:
        ```python
        poly_data = DmPolyData()
        num_lines = poly_data.get_number_of_lines()
        ```
        """
        return self._obj.GetNumberOfLines()

    def get_number_of_polys(self) -> int:
        """
        获取多边形数量
        :return: 多边形数量(整数)

        example:
        ```python
        poly_data = DmPolyData()
        num_polys = poly_data.get_number_of_polys()
        ```
        """
        return self._obj.GetNumberOfPolys()

    def get_number_of_points(self) -> int:
        """
        获取点的总数量
        :return: 点数量(整数)

        example:
        ```python
        poly_data = DmPolyData()
        num_points = poly_data.get_number_of_points()
        ```
        """
        return self._obj.GetNumberOfPoints()

    def get_bounds(self) -> list[float]:
        """
        获取数据的包围盒
        :return: 包围盒坐标列表 [min_x, max_x, min_y, max_y, min_z, max_z]

        example:
        ```python
        poly_data = DmPolyData()
        bounds = poly_data.get_bounds()
        ```
        """
        return self._obj.GetBounds()

    # ---------------------- 单元格插入 ----------------------
    def insert_next_vert_cell(self, point_indexes: list[int]) -> None:
        """
        插入顶点单元格
        :param point_indexes: 点索引列表(整数列表)

        example:
        ```python
        poly_data = DmPolyData()
        poly_data.insert_next_vert_cell([0, 1, 2])
        ```
        """
        self._obj.InsertNextVertCell(point_indexes)

    def insert_next_line_cell(self, point_indexes: list[int]) -> None:
        """
        插入线段单元格
        :param point_indexes: 点索引列表(整数列表)

        example:
        ```python
        poly_data = DmPolyData()
        poly_data.insert_next_line_cell([0, 1, 2])
        ```
        """
        self._obj.InsertNextLineCell(point_indexes)

    def insert_next_poly_cell(self, point_indexes: list[int]) -> None:
        """
        插入多边形单元格
        :param point_indexes: 点索引列表(整数列表)

        example:
        ```python
        poly_data = DmPolyData()
        poly_data.insert_next_poly_cell([0, 1, 2])
        ```
        """
        self._obj.InsertNextPolyCell(point_indexes)

    # ---------------------- 点操作 ----------------------
    def insert_unique_point(self, point: DmDPoint) -> int:
        """
        插入唯一的点(自动去重)
        :param point: 待插入的点(DmDPoint实例)
        :return: 点的唯一ID(整数)

        example:
        ```python
        poly_data = DmPolyData()
        point_id = poly_data.insert_unique_point(DmDPoint(0.0, 0.0, 0.0))
        ```
        """
        return self._obj.InsertUniquePoint(point._obj)

    def get_point(self, point_id: int) -> DmDPoint:
        """
        根据ID获取点
        :param point_id: 点的唯一ID(整数)
        :return: 对应的DmDPoint实例

        example:
        ```python
        poly_data = DmPolyData()
        point_id = poly_data.insert_unique_point(DmDPoint(0.0, 0.0, 0.0))
        point = poly_data.get_point(point_id)
        ```
        """
        cpp_point = self._obj.GetPoint(point_id)
        return DmDPoint._from_obj(cpp_point)

    def set_dm_points(self, points: DmPoints) -> None:
        """
        设置关联的点集合
        :param points: DmPoints实例

        example:
        ```python
        poly_data = DmPolyData()
        points = DmPoints()
        poly_data.set_dm_points(points)
        ```
        """
        self._obj.SetDmPoints(points._obj)

    def get_dm_points(self) -> DmPoints:
        """
        获取关联的点集合
        :return: DmPoints实例

        example:
        ```python
        poly_data = DmPolyData()
        points = DmPoints()
        poly_data.set_dm_points(points)
        dm_points = poly_data.get_dm_points()
        ```
        """
        cpp_points = self._obj.GetDmPoints()
        return DmPoints._from_obj(cpp_points)

    # ---------------------- 多边形数据获取 ----------------------
    def get_poly_cell(self, cell_index: int) -> list[int]:
        """
        获取指定索引的多边形单元格的点索引
        :param cell_index: 单元格索引(整数)
        :return: 点索引列表(整数列表)

        example:
        ```python
        poly_data = DmPolyData()
        cell_index = 0
        point_indexes = poly_data.get_poly_cell(cell_index)
        ```
        """
        return self._obj.GetPolyCell(cell_index)

    # ---------------------- 提取多段线 ----------------------
    def extract_polylines(self) -> list[DmDbPolyline]:
        """
        提取多段线实体
        :return: 多段线列表,每个元素为DmDbPolyline实例

        example:
        ```python
        poly_data = DmPolyData()
        polylines = poly_data.extract_polylines()
        ```
        """
        cpp_list = self._obj.ExtractPolylines()
        return [DmDbPolyline._from_obj(item) for item in cpp_list]

    # ---------------------- 字符串表示 ----------------------
    def __repr__(self) -> str:
        """
        字符串表示
        :return: 多边形数据的标准字符串表示
        """
        return self._obj.__repr__()

    # ---------------------- 桥接方法 ----------------------
    @classmethod
    def _from_obj(cls, obj):
        """
        原生对象创建封装实例
        :param obj: 原生dmPolyData对象
        :return: DmPolyData实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

__init__()

构造函数:初始化多边形数据对象 :return: None

Source code in dimine_python_sdk\lib\types\entity.py
80
81
82
83
84
85
def __init__(self):
    """
    构造函数:初始化多边形数据对象
    :return: None
    """
    self._obj = Dm.dmPolyData()

__repr__()

字符串表示 :return: 多边形数据的标准字符串表示

Source code in dimine_python_sdk\lib\types\entity.py
312
313
314
315
316
317
def __repr__(self) -> str:
    """
    字符串表示
    :return: 多边形数据的标准字符串表示
    """
    return self._obj.__repr__()

extract_polylines()

提取多段线实体 :return: 多段线列表,每个元素为DmDbPolyline实例

example:

poly_data = DmPolyData()
polylines = poly_data.extract_polylines()
Source code in dimine_python_sdk\lib\types\entity.py
297
298
299
300
301
302
303
304
305
306
307
308
309
def extract_polylines(self) -> list[DmDbPolyline]:
    """
    提取多段线实体
    :return: 多段线列表,每个元素为DmDbPolyline实例

    example:
    ```python
    poly_data = DmPolyData()
    polylines = poly_data.extract_polylines()
    ```
    """
    cpp_list = self._obj.ExtractPolylines()
    return [DmDbPolyline._from_obj(item) for item in cpp_list]

get_bounds()

获取数据的包围盒 :return: 包围盒坐标列表 [min_x, max_x, min_y, max_y, min_z, max_z]

example:

poly_data = DmPolyData()
bounds = poly_data.get_bounds()
Source code in dimine_python_sdk\lib\types\entity.py
166
167
168
169
170
171
172
173
174
175
176
177
def get_bounds(self) -> list[float]:
    """
    获取数据的包围盒
    :return: 包围盒坐标列表 [min_x, max_x, min_y, max_y, min_z, max_z]

    example:
    ```python
    poly_data = DmPolyData()
    bounds = poly_data.get_bounds()
    ```
    """
    return self._obj.GetBounds()

get_data_type()

获取多边形数据类型 :return: 数据类型编码(整数)

example:

poly_data = DmPolyData()
data_type = poly_data.get_data_type()
Source code in dimine_python_sdk\lib\types\entity.py
88
89
90
91
92
93
94
95
96
97
98
99
def get_data_type(self) -> int:
    """
    获取多边形数据类型
    :return: 数据类型编码(整数)

    example:
    ```python
    poly_data = DmPolyData()
    data_type = poly_data.get_data_type()
    ```
    """
    return self._obj.GetDataType()

get_dm_points()

获取关联的点集合 :return: DmPoints实例

example:

poly_data = DmPolyData()
points = DmPoints()
poly_data.set_dm_points(points)
dm_points = poly_data.get_dm_points()
Source code in dimine_python_sdk\lib\types\entity.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def get_dm_points(self) -> DmPoints:
    """
    获取关联的点集合
    :return: DmPoints实例

    example:
    ```python
    poly_data = DmPolyData()
    points = DmPoints()
    poly_data.set_dm_points(points)
    dm_points = poly_data.get_dm_points()
    ```
    """
    cpp_points = self._obj.GetDmPoints()
    return DmPoints._from_obj(cpp_points)

get_number_of_cells()

获取单元格数量 :return: 单元格数量(整数)

example:

poly_data = DmPolyData()
num_cells = poly_data.get_number_of_cells()
Source code in dimine_python_sdk\lib\types\entity.py
101
102
103
104
105
106
107
108
109
110
111
112
def get_number_of_cells(self) -> int:
    """
    获取单元格数量
    :return: 单元格数量(整数)

    example:
    ```python
    poly_data = DmPolyData()
    num_cells = poly_data.get_number_of_cells()
    ```
    """
    return self._obj.GetNumberOfCells()

get_number_of_lines()

获取线段数量 :return: 线段数量(整数)

example:

poly_data = DmPolyData()
num_lines = poly_data.get_number_of_lines()
Source code in dimine_python_sdk\lib\types\entity.py
127
128
129
130
131
132
133
134
135
136
137
138
def get_number_of_lines(self) -> int:
    """
    获取线段数量
    :return: 线段数量(整数)

    example:
    ```python
    poly_data = DmPolyData()
    num_lines = poly_data.get_number_of_lines()
    ```
    """
    return self._obj.GetNumberOfLines()

get_number_of_points()

获取点的总数量 :return: 点数量(整数)

example:

poly_data = DmPolyData()
num_points = poly_data.get_number_of_points()
Source code in dimine_python_sdk\lib\types\entity.py
153
154
155
156
157
158
159
160
161
162
163
164
def get_number_of_points(self) -> int:
    """
    获取点的总数量
    :return: 点数量(整数)

    example:
    ```python
    poly_data = DmPolyData()
    num_points = poly_data.get_number_of_points()
    ```
    """
    return self._obj.GetNumberOfPoints()

get_number_of_polys()

获取多边形数量 :return: 多边形数量(整数)

example:

poly_data = DmPolyData()
num_polys = poly_data.get_number_of_polys()
Source code in dimine_python_sdk\lib\types\entity.py
140
141
142
143
144
145
146
147
148
149
150
151
def get_number_of_polys(self) -> int:
    """
    获取多边形数量
    :return: 多边形数量(整数)

    example:
    ```python
    poly_data = DmPolyData()
    num_polys = poly_data.get_number_of_polys()
    ```
    """
    return self._obj.GetNumberOfPolys()

get_number_of_verts()

获取顶点数量 :return: 顶点数量(整数)

example:

poly_data = DmPolyData()
num_verts = poly_data.get_number_of_verts()
Source code in dimine_python_sdk\lib\types\entity.py
114
115
116
117
118
119
120
121
122
123
124
125
def get_number_of_verts(self) -> int:
    """
    获取顶点数量
    :return: 顶点数量(整数)

    example:
    ```python
    poly_data = DmPolyData()
    num_verts = poly_data.get_number_of_verts()
    ```
    """
    return self._obj.GetNumberOfVerts()

get_point(point_id)

根据ID获取点 :param point_id: 点的唯一ID(整数) :return: 对应的DmDPoint实例

example:

poly_data = DmPolyData()
point_id = poly_data.insert_unique_point(DmDPoint(0.0, 0.0, 0.0))
point = poly_data.get_point(point_id)
Source code in dimine_python_sdk\lib\types\entity.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def get_point(self, point_id: int) -> DmDPoint:
    """
    根据ID获取点
    :param point_id: 点的唯一ID(整数)
    :return: 对应的DmDPoint实例

    example:
    ```python
    poly_data = DmPolyData()
    point_id = poly_data.insert_unique_point(DmDPoint(0.0, 0.0, 0.0))
    point = poly_data.get_point(point_id)
    ```
    """
    cpp_point = self._obj.GetPoint(point_id)
    return DmDPoint._from_obj(cpp_point)

get_poly_cell(cell_index)

获取指定索引的多边形单元格的点索引 :param cell_index: 单元格索引(整数) :return: 点索引列表(整数列表)

example:

poly_data = DmPolyData()
cell_index = 0
point_indexes = poly_data.get_poly_cell(cell_index)
Source code in dimine_python_sdk\lib\types\entity.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
def get_poly_cell(self, cell_index: int) -> list[int]:
    """
    获取指定索引的多边形单元格的点索引
    :param cell_index: 单元格索引(整数)
    :return: 点索引列表(整数列表)

    example:
    ```python
    poly_data = DmPolyData()
    cell_index = 0
    point_indexes = poly_data.get_poly_cell(cell_index)
    ```
    """
    return self._obj.GetPolyCell(cell_index)

insert_next_line_cell(point_indexes)

插入线段单元格 :param point_indexes: 点索引列表(整数列表)

example:

poly_data = DmPolyData()
poly_data.insert_next_line_cell([0, 1, 2])
Source code in dimine_python_sdk\lib\types\entity.py
193
194
195
196
197
198
199
200
201
202
203
204
def insert_next_line_cell(self, point_indexes: list[int]) -> None:
    """
    插入线段单元格
    :param point_indexes: 点索引列表(整数列表)

    example:
    ```python
    poly_data = DmPolyData()
    poly_data.insert_next_line_cell([0, 1, 2])
    ```
    """
    self._obj.InsertNextLineCell(point_indexes)

insert_next_poly_cell(point_indexes)

插入多边形单元格 :param point_indexes: 点索引列表(整数列表)

example:

poly_data = DmPolyData()
poly_data.insert_next_poly_cell([0, 1, 2])
Source code in dimine_python_sdk\lib\types\entity.py
206
207
208
209
210
211
212
213
214
215
216
217
def insert_next_poly_cell(self, point_indexes: list[int]) -> None:
    """
    插入多边形单元格
    :param point_indexes: 点索引列表(整数列表)

    example:
    ```python
    poly_data = DmPolyData()
    poly_data.insert_next_poly_cell([0, 1, 2])
    ```
    """
    self._obj.InsertNextPolyCell(point_indexes)

insert_next_vert_cell(point_indexes)

插入顶点单元格 :param point_indexes: 点索引列表(整数列表)

example:

poly_data = DmPolyData()
poly_data.insert_next_vert_cell([0, 1, 2])
Source code in dimine_python_sdk\lib\types\entity.py
180
181
182
183
184
185
186
187
188
189
190
191
def insert_next_vert_cell(self, point_indexes: list[int]) -> None:
    """
    插入顶点单元格
    :param point_indexes: 点索引列表(整数列表)

    example:
    ```python
    poly_data = DmPolyData()
    poly_data.insert_next_vert_cell([0, 1, 2])
    ```
    """
    self._obj.InsertNextVertCell(point_indexes)

insert_unique_point(point)

插入唯一的点(自动去重) :param point: 待插入的点(DmDPoint实例) :return: 点的唯一ID(整数)

example:

poly_data = DmPolyData()
point_id = poly_data.insert_unique_point(DmDPoint(0.0, 0.0, 0.0))
Source code in dimine_python_sdk\lib\types\entity.py
220
221
222
223
224
225
226
227
228
229
230
231
232
def insert_unique_point(self, point: DmDPoint) -> int:
    """
    插入唯一的点(自动去重)
    :param point: 待插入的点(DmDPoint实例)
    :return: 点的唯一ID(整数)

    example:
    ```python
    poly_data = DmPolyData()
    point_id = poly_data.insert_unique_point(DmDPoint(0.0, 0.0, 0.0))
    ```
    """
    return self._obj.InsertUniquePoint(point._obj)

set_dm_points(points)

设置关联的点集合 :param points: DmPoints实例

example:

poly_data = DmPolyData()
points = DmPoints()
poly_data.set_dm_points(points)
Source code in dimine_python_sdk\lib\types\entity.py
250
251
252
253
254
255
256
257
258
259
260
261
262
def set_dm_points(self, points: DmPoints) -> None:
    """
    设置关联的点集合
    :param points: DmPoints实例

    example:
    ```python
    poly_data = DmPolyData()
    points = DmPoints()
    poly_data.set_dm_points(points)
    ```
    """
    self._obj.SetDmPoints(points._obj)