ElAmigo Posted March 7 Posted March 7 Hello, I want to write a code that prompts the user to select an object or objects and scales it by variable called "factor" and moves it to a point specified by the user. I hope someone can help me because I'm stuck. I have a code that works but it asks for 2 points and I just want to select the objects the 'normal' way. I used dutch names for variables so I translated it with AI: (defun c:EnlargeAndMoveObjects (/ oldScale newScale oldFactor newFactor factor p1 p2 selection basePoint newPoint displacementVector) (c:fetchAttributeValue "Initial_View_Scale") ; Assumption: c:fetchAttributeValue sets a global variable NewVal (setq Scale NewVal) ;; Find the position of ":" in Scale and extract the old factor (setq pos (vl-string-search ":" Scale)) (setq oldFactor (read (substr Scale (+ pos 2)))) ;; Enter the new scale and extract the new factor (setq newScale (getstring "\nEnter the new scale (e.g., 1:10): ")) (setq pos (vl-string-search ":" newScale)) (setq newFactor (read (substr newScale (+ pos 2)))) ;; Calculate the magnification factor (setq factor (/ (float newFactor) oldFactor)) ;; Ask the user to define the area by selecting two points (setq p1 (getpoint "\nSelect the first point of the area: ")) (setq p2 (getpoint p1 "\nSelect the diagonal opposite point of the area: ")) ;; Select all objects within the specified area (setq selection (ssget "C" p1 p2)) ;; Determine the base point for scaling (the middle of the area) (setq basePoint (list (/ (+ (car p1) (car p2)) 2) (/ (+ (cadr p1) (cadr p2)) 2))) ;; If objects are selected, scale them (if selection (progn ;; Scale all selected objects (command "_scale" selection "" basePoint factor) ;; Ask the user for a new point for relocation (setq newPoint (getpoint "\nSelect a new point to move the objects to: ")) ;; Calculate the displacement vector (setq displacementVector (list (- (car newPoint) (car basePoint)) (- (cadr newPoint) (cadr basePoint)))) ;; Move the selected objects (command "_move" selection "" "" displacementVector) (princ (strcat "\nObjects enlarged by a factor of: " (rtos factor) " and moved.")) ) (princ "\nNo objects selected.") ) (princ) ) Quote
CyberAngel Posted March 7 Posted March 7 First, remove the parameters in the ssget function: (setq selection (ssget)) This gives you the standard prompt "Select objects:" and lets the user pick objects normally. Also remove the two statements before it, since you won't use p1 and p2. You can remove them from the list of local variables. Second, replace the statement (setq basePoint... ) with a statement that gets a base point from the user. Use the statement that gets newPoint if you need a template. Everything else should work the way the original code did. If you have a problem, let us know. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.