dexus Posted November 11, 2015 Posted November 11, 2015 Hello, I'm using a function to quickly divide a line. The divisions are rounded to a chosen distance. (defun inzetpunten (/ obj num div objg) (while (not obj) (setq obj(entsel)) (if obj (progn (setq objg (entget (car obj))) (setq num (/ (distance (cdr (assoc 10 objg)) (cdr (assoc 11 objg))) 400)) ; target distance = 400 (if (< 0.5 (- num (fix num))) (setq div (1+ (fix num))) (setq div (fix num))) (if (> 2 div) (setq div 2)) (command "divide" obj div) ) (princ "\nNothing was selected, Please select a line!")) ) (princ) ) Now this works great. But I have a drawing with the same length lines, only one divides into 6 and the other divides into 7 parts. I got a vlax dump of the 2 lines: Select object: ; IAcadLine: AutoCAD Line Interface ; Property values: ; Angle (RO) = 3.14159 ; Application (RO) = #<VLA-OBJECT IAcadApplication 000000013fd89110> [color=red]; Delta (RO) = (-3000.0 9.09495e-013 0.0)[/color] ; Document (RO) = #<VLA-OBJECT IAcadDocument 000000002f573368> ; EndPoint = (-14065.0 5567.73 0.0) ; EntityTransparency = "ByLayer" ; Handle (RO) = "DB11" ; HasExtensionDictionary (RO) = 0 ; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 0000000037a10f78> ; Layer = "HULPLIJN" ; Length (RO) = 3000.0 ; Linetype = "ByLayer" ; LinetypeScale = 1.0 ; Lineweight = -1 ; Material = "ByLayer" ; Normal = (0.0 0.0 1.0) ; ObjectID (RO) = 44 ; ObjectName (RO) = "AcDbLine" ; OwnerID (RO) = 43 ; PlotStyleName = "ByLayer" ; StartPoint = (-11065.0 5567.73 0.0) ; Thickness = 0.0 ; TrueColor = #<VLA-OBJECT IAcadAcCmColor 0000000037a13370> ; Visible = -1 T ; Property values: ; Angle (RO) = 3.14159 ; Application (RO) = #<VLA-OBJECT IAcadApplication 000000013fd89110> [color=red]; Delta (RO) = (-3000.0 0.0 0.0)[/color] ; Document (RO) = #<VLA-OBJECT IAcadDocument 000000002f573368> ; EndPoint = (-14065.0 5685.33 0.0) ; EntityTransparency = "ByLayer" ; Handle (RO) = "DB3C" ; HasExtensionDictionary (RO) = 0 ; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 0000000037a13078> ; Layer = "HULPLIJN" ; Length (RO) = 3000.0 ; Linetype = "ByLayer" ; LinetypeScale = 1.0 ; Lineweight = -1 ; Material = "ByLayer" ; Normal = (0.0 0.0 1.0) ; ObjectID (RO) = 42 ; ObjectName (RO) = "AcDbLine" ; OwnerID (RO) = 43 ; PlotStyleName = "ByLayer" ; StartPoint = (-11065.0 5685.33 0.0) ; Thickness = 0.0 ; TrueColor = #<VLA-OBJECT IAcadAcCmColor 0000000037f29450> ; Visible = -1 T The only difference seems to be the delta, how can I work around this bug in my lisp? Thanks in advance! Quote
Lee Mac Posted November 11, 2015 Posted November 11, 2015 Change: (if (< 0.5 (- num (fix num))) (setq div (1+ (fix num))) (setq div (fix num))) to: (setq div (atoi (rtos num 2 0))) Quote
dexus Posted November 11, 2015 Author Posted November 11, 2015 That is a much better way of rounding, thanks! I love your website by the way, it has been really helpful learning autolisp. Quote
Lee Mac Posted November 11, 2015 Posted November 11, 2015 Thank you - I appreciate your positive feedback for my site! 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.