Jump to content

Using Arraypath function via scripting, duplicating lines are created in opposite direction of curve path


Recommended Posts

Posted (edited)
(defun c:AUTOHPA ( / objLayer pathLayer objSS pathSS objToArray pathCurve pathLength )
  (setvar "CMDECHO" 0)

  ;; Define your custom layer names here
  (setq objLayer  "V1")  ; <-- Replace with your object layer name
  (setq pathLayer "P1")    ; <-- Replace with your path layer name
  
   ;; Number of items
  (setq items 10)

  ;; Automatically select everything on the object layer
  (setq objSS (ssget "_X" (list '(0 . "*") (cons 8 objLayer))))
  
  ;; Automatically select the first/only object on the path layer
  (setq pathSS (ssget "_X" (list '(0 . "*") (cons 8 pathLayer))))

  (princ "working01")
  ;; Check if both selections actually found objects
  (if (and objSS pathSS)
    (progn
      ;; Get the first entity name from the path selection set
      (setq pathCurve (ssname pathSS 0))
      
       ;; 3. Calculate the exact length of the path object automatically
      (setq pathLength (vlax-curve-getDistAtParam pathCurve (vlax-curve-getEndParam pathCurve)))
      (princ pathLength)
      
      (princ "working02")
      ;; Execute the array using the full object selection set
      (command "._ARRAYPATH" objSS "" pathCurve "M" "M" "I" items pathLength "" "X")

      (princ "\nArray completed successfully using layers.")

    )
    (princ "\nError: Objects or Path curve not found on the specified layers.")
  )

  (setvar "CMDECHO" 1)
  (princ)
)


 

Edited by SLW210
Added Code Tags!!
Posted

Please use Code Tags when posting code. (use <> in the Editor)

 

Do you have a drawing with a before and after?

Posted

Green line should follow white curve path instead the duplicating lines are offsetting in opposite direction of curve

5.png

4.png

Posted

That's an Image, not a drawing.

 

But since you want guesses only, my WAG is the direction of whatever object you are using for the 'curve path".

Posted

manually arraypath is working fine but only while script running it is not working. At some location of layout it is working and at other location same script is not working.

test_01.dwg

Posted

curve direction reverse using pedit I have tried but not working. I think script is not working because of default base point selection.

Posted

At a glance a couple of comments;

 

Dont use "X" in the ssget. so you can select one or more objects. 

 

Ok the reason the objects array backwards is because of the arc direction, I tested by arraying objects two times and pick an arc on both ends and yes array went wrong way for one end pick. So there is a way around it, select an end you imply a direction, so use a pause to select path.

 

Dont use the ssget to get path object. Rather use Entsel or even getpoint. 

My take on the task.

(defun c:AUTOHPA ( / objLayer objSS pt pathCurve pathLength items)
  (setvar "CMDECHO" 0)
  (setq objlayer (cdr (assoc 8 (entget (car (entsel "\nPick an object for layer name "))))))
  (princ "\nPick objects to Array ")
  (setq objSS (ssget (list (cons 8 objLayer))))
  (if (= objSS nil)
  (progn (alert "No objects selected that match layer name \nWill now exit")(exit))
  (progn
    (setq items (getint "\nEnter how many items "))
    (setq pathCurve (entsel "\nPick path near an end for direction "))
    (setq pt (cadr pathCurve))
    (setq path (vlax-ename->vla-object (car pathcurve)))
    (setq pathLength (vlax-curve-getDistAtParam path (vlax-curve-getEndParam path)))
    (princ pathLength)
    (command "._ARRAYPATH"  objSS "" pt "M" "D" "I" items "")
    (princ "\nArray completed successfully using layers.")
  )
  )
  (setvar "CMDECHO" 1)
  (princ)
)
(c:AUTOHPA)

 

 

 

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...