Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp not working in Autocad 2014

1 REPLY 1
Reply
Message 1 of 2
Anonymous
388 Views, 1 Reply

Lisp not working in Autocad 2014

Hi,

 

We have been using the attached lisp for a while but we have recently updated to 2014 and now it seems to not work correctly. It runs through but doesnt give the correct result.

 

It is used for quickly annotating the gradient along pipe runs by selecting text levels, length of run etc.

 

Can anyone please help!

 

Thanks in advance

1 REPLY 1
Message 2 of 2
BlackBox_
in reply to: Anonymous

Welcome to the Autodesk forums. 

 

 

I didn't have a sample drawing to test, so unsure why your routine isn't working.

 

This seems to work, using Civil 3D 2014, and includes a few enhancements:

 

(vl-load-com)

(defun c:SLABEL	(/ *error* ss1 ss2 pt1 pt2 diameter material osmode
		 acDoc layerName oLayer	oText
		)

  (defun *error* (msg)
    (if	oText
      (vla-delete oText)
    )
    (and osmode (setvar 'osmode osmode))
    (if	acDoc
      (vla-endundomark acDoc)
    )
    (cond ((not msg))							; Normal exit
	  ((member msg '("Function cancelled" "quit / exit abort")))	; <esc> or (quit)
	  ((princ (strcat "\n** Error: " msg " ** ")))			; Fatal error, display it
    )
    (princ)
  )

  (if
    (and
      (princ "\nSelect upper level text: ")
      (setq ss1 (ssget ":S:E" '((0 . "MTEXT,TEXT"))))
      (princ "\nSelect lower level text: ")
      (setq ss2 (ssget ":S:E" '((0 . "MTEXT,TEXT"))))
      (setq pt1 (getpoint "\nSpecify pipe start (left): "))
      (not (initget 32))
      (setq pt2 (getpoint pt1 "\nSpecify pipe end (right): "))
      (setq diameter (getint "\nEnter pipe diameter: "))
      (not (initget 1 "Clay cOncrete Plastic"))
      (setq material
	     (getkword
	       "\nEnter pipe material [Clay/cOncrete/Plastic]: "
	     )
      )
      (setq osmode (getvar 'osmode))
      (setvar 'osmode 0)
    )
     (progn
       (vla-startundomark
	 (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
       )
       (setq oLayer
	      (vla-add (vla-get-layers acDoc) (setq layerName "TEXT"))
       )
       (vla-put-color oLayer acyellow)
       (setq oText
	      (vla-addtext
		(vlax-get acDoc
			  (if (= 1 (getvar 'cvport))
			    'paperspace
			    'modelspace
			  )
		)
		(strcat	"%%C"
			(itoa diameter)
			" "
			(if (= "cOncrete" material)
			  "Concrete"
			  material
			)
			" 1:"
			(itoa
			  (fix
			    (/ 1.0
			       (/ (- (atof
				       (cdr (assoc 1 (entget (ssname ss1 0))))
				     )
				     (atof
				       (cdr (assoc 1 (entget (ssname ss2 0))))
				     )
				  )
				  (distance pt1 pt2)
			       )
			    )
			  )
			)
		)
		(vlax-3d-point '(0 0 0))
		0.3
	      )
       )
       (vla-put-alignment oText acalignmentcenter)
       (vla-put-layer oText layerName)
       (vla-put-rotation oText (angle pt1 pt2))
       (vla-move
	 oText
	 (vla-get-textalignmentpoint oText)
	 (vlax-3d-point (mapcar '* (mapcar '+ pt1 pt2) '(0.5 0.5 0.5)))
       )
       (setq oText (command "._move"
			    (vlax-vla-object->ename oText)
			    ""
			    (vlax-get oText 'textalignmentpoint)
			    pause
		   )
       )
     )
  )
  (*error* nil)
)

 

 

You could remove the MOVE Command call, and replace with Acet-Ss-Drag-Move if you'd prefer, but that adds another localized variable (for the implicit secondary vla-Move call).

 

Cheers



"How we think determines what we do, and what we do determines what we get."

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

Post to forums  

Autodesk Design & Make Report

”Boost