Jump to content

Divide function


dexus

Recommended Posts

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!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...