;;程序功能：运行物件命令,自动配置常用绘图环与物件一致

;;主程序
(defun c:fsxm_cd (/ *error* cmd map color data en ltype lweight name nm obj *DimStyles*)
  (setq *DimStyles* (vla-get-DimStyles *doc*))
  (setq *error* strcat)
  (setq en (car (entsel)))
  (setq data (entget en))
  (setq obj (vlax-ename->vla-object en))
  ;;layer
  (setvar "clayer" (fsxm-getdxf 8 data))
  ;;color
  (setq color (fsxm-getdxf 62 data))
  (cond	((null color) (setq color "ByLayer"))
	((= 0 color) (setq color "ByBlock"))
  )
  (setvar "cecolor" (vl-princ-to-string color))
  ;;ltype
  (setq ltype (fsxm-getdxf 6 data))
  (or ltype (setq ltype "ByLayer"))
  (setvar "celtype" ltype)
  ;;lweight
  (setq lweight (fsxm-getdxf 370 data))
  (or lweight (setq lweight -1))
  (setvar "celweight" lweight)
  ;;textstyle
  (vl-catch-all-apply
    '(lambda () (setvar "textstyle" (fsxm-getdxf 7 data)))
  )
  ;;dimstyle
  (vl-catch-all-apply
    '(lambda ()
       (setq dimstyle (fsxm-getdxf 3 data))
       (vla-put-ActiveDimStyle
	 *doc*
	 (vla-item *DimStyles* dimstyle)
       )
     )
  )
  ;;匹配命令
  (setq name (fsxm-getdxf 0 data))
  (setq nm (vla-get-ObjectName obj))
  (defun send (cmd)
    (vla-SendCommand *doc* (strcat "." cmd " "))
  )
  (setq	map '(("AcDbHatch" "BHATCH")
	      ("AcDbPolyline" "PLINE")
	      ("AcDb3dPolyline" "3DPOLY")
	      ("AcDbRotatedDimension" "DIMLINEAR")
	      ("AcDbAlignedDimension" "DIMALIGNED")
	      ("AcDbOrdinateDimension" "DIMORDINATE")
	      ("AcDbRadialDimension" "DIMRADIUS")
	      ("AcDbDiametricDimension" "DIMDIAMETER")
	      ("AcDb3PointAngularDimension" "DIMANGULAR")
	     )
  )
  (cond	((setq cmd (assoc nm map)) (send (cadr cmd)))
	((getcname name) (send name))
	(t (princ (strcat "\n本程序还未收录: " name " (" nm ")")))
  )
  (princ)
)