@@ -788,6 +788,59 @@ def add_line(self, start_point, end_point):
788788 return line
789789 except Exception as e :
790790 raise CADException (f"Error adding line: { e } " )
791+
792+ def _ensure_linetype_loaded (self , linetype_name ):
793+ """
794+ Ensures a linetype is loaded in the document.
795+ Args:
796+ linetype_name (str): The name of the linetype to load.
797+ """
798+ try :
799+ linetypes = self .doc .Linetypes
800+ linetype_exists = False
801+ for lt in linetypes :
802+ if lt .Name .lower () == linetype_name .lower ():
803+ linetype_exists = True
804+ break
805+
806+ if not linetype_exists :
807+ try :
808+ self .doc .Linetypes .Load (linetype_name , "acad.lin" )
809+ except :
810+ try :
811+ self .doc .Linetypes .Load (linetype_name , "acadiso.lin" )
812+ except :
813+ pass
814+ except :
815+ pass # Silently continue if loading fails
816+
817+ def set_linetype (self , obj , linetype ):
818+ """
819+ Sets the linetype of an object, automatically loading it if needed.
820+
821+ Args:
822+ obj: The AutoCAD object to modify.
823+ linetype (LineStyle or str): The linetype to apply.
824+
825+ Raises:
826+ CADException: If the linetype cannot be set.
827+
828+ Example:
829+ >>> acad = AutoCAD()
830+ >>> line = acad.add_line(APoint(0, 0, 0), APoint(100, 0, 0))
831+ >>> acad.set_linetype(line, LineStyle.DASHED)
832+ """
833+ try :
834+ # Handle both LineStyle enum and string
835+ linetype_name = linetype .value if isinstance (linetype , LineStyle ) else linetype
836+
837+ # Ensure linetype is loaded
838+ self ._ensure_linetype_loaded (linetype_name )
839+
840+ # Apply the linetype
841+ obj .Linetype = linetype_name
842+ except Exception as e :
843+ raise CADException (f"Error setting linetype: { e } " )
791844
792845 def add_rectangle (self , lower_left , upper_right ):
793846 """
0 commit comments