谢谢你,伙计!
现在,我的问题似乎有点讽刺,但以下是我正在编写的代码的最终结果:
- ; VLD_Offset
- ; Perform offset, by detecting with cursor, from which side the entity is selected,
- ; and then the entity is offseted, corresponding to that side/orientation.
- (defun C:test ( / *error* oldcmd oldclp oldpxsz off-dist ent vla-obj P-pt C-pt T-pt )
- (vl-load-com)
- (defun *error* ( msg )
- (if oldcmd (setvar 'cmdecho oldcmd))
- (if oldclp (setvar 'clipromptlines oldclp))
- (if oldpxsz (setvar 'pickbox oldpxsz))
- (if (not (member msg '("Function cancelled" "quit / exit abort")))
- (princ (strcat "\nError: " msg))
- )
- (princ)
- )
- (initget 1)
- (if (setq off-dist (getreal "\nSpecify offset distance: "))
- (progn
- (setvar 'errno 0)
- (setq oldcmd (getvar 'cmdecho))
- (setvar 'cmdecho 0)
- (setq oldclp (getvar 'clipromptlines))
- (setvar 'clipromptlines 1)
- (setq oldpxsz (getvar 'pickbox)) ; default value is 3
- (setvar 'pickbox (* oldpxsz 3))
- (while T
- (while
- (not
- (and
- (setq ent (entsel "\nPick an entity to offset: "))
- (member (cdr (assoc 0 (entget (car ent)))) (list "LINE" "LWPOLYLINE" "SPLINE" "CIRCLE" "ARC" "XLINE" "RAY"))
- )
- )
- (if (or (= (getvar 'errno) 7) (null (car ent))) (princ "\nYou missed, try again!") )
- ); while
- (progn
- (setq vla-obj (vlax-ename->vla-object (car ent)))
- (setq P-pt (cadr ent)) ; pick point
- (setq C-pt (vlax-curve-getClosestPointTo vla-obj P-pt)) ; closest point
- (setq T-pt (polar C-pt (angle C-pt P-pt) off-dist)) ; trough point
- (vl-cmdf "_.OFFSET" "T" ent T-pt "E")
- )
- ); while T
- ); progn
- ); if off-dist
- (princ)
- ); defun
|