Jump to content

Faster way of copying objects?? and selecting lines on an xrefered file


Isaac26a

Recommended Posts

I want to know if any of you can help me to make this piece of code work faster, it does what is needed but takes some time to achieve the task, I use it to copy Surface Label Points (0 . "AECC_SURFACE_ELEVATION_LABEL") on Civil3D but it can also be circles, by the way I couldn't find an insertion point for this (surface label points) elements so I had to ask for an insertion point, anyway I'll get by just by making it faster.

 

And also I wanted to select lines that are in a xref but didn't find out how, It would be also helpfull to know how to.

 

Thanks in advance for taking your time and helping.

;;; Copy multiple objects on start and end points of lines on a selected layer
;;; 20220212 By Isaac A.
(defun c:c2l ( / ent lst lyr pt pt1 ss ss1 )
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")

   (setvar "osmode" 37)
   (princ "\nSelect the object(s) to copy. ")
   (setq ss1 (ssget))
   (setq pt (getpoint "\nSelect a base point: "))
   (setq ent (entsel "\nPick a line on the target layer: "))
   (setq lyr (cdr (assoc 8 (entget (car ent)))))
   (if (setq ss (ssget "_X" (list '(0 . "LINE") (cons 8 lyr))))
      (progn
         (foreach line (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
            (setq lst (cons (cdr (assoc 10 (entget line))) lst)
                  lst (cons (cdr (assoc 11 (entget line))) lst)
            )
         )
         (foreach pt1 lst
            (vl-cmdf "_.copy" ss1 "" pt pt1)
         )
      )
   )

   (vl-cmdf "_.undo" "_end")
   (princ)
)

 

Also leave you an example file and the xref file.

20220204 base.dwg example.dwg

exampl01.jpg

Edited by Isaac26a
Link to comment
Share on other sites

Are you binding the xref? maybe ssget works different in AutoCAD but won't pick anything up in blocks or xref's in bricscad.

 

1 hour ago, Isaac26a said:

And also I wanted to select lines that are in a xref but didn't find out how, It would be also helpfull to know how to.

 

Using nentsel to select nested objects in blocks and xref's.

(setq ent (nentsel "\nPick a line on the target layer: "))

 

Link to comment
Share on other sites

3 hours ago, mhupp said:

Are you binding the xref? maybe ssget works different in AutoCAD but won't pick anything up in blocks or xref's in bricscad.

 

 

Using nentsel to select nested objects in blocks and xref's.

(setq ent (nentsel "\nPick a line on the target layer: "))

 

 

The thing is I don't really know if it is possible, I thought that maybe there is a chance of doing it, but at least I can have a start by using nentsel. Thanks. Mhupp

Link to comment
Share on other sites

Was thinking about how to do this.

 

  • insert xref as a block using a different name. insert at '(0 0 0)
  • use nentsel to select the line in the block
  • use visual lisp to explode block
  • this will allow you to step though each item and pull points. example
  • delete exploded entity's as you go
  • delete inserted block
  • copy item to points in list.

 

Link to comment
Share on other sites

17 hours ago, mhupp said:

Was thinking about how to do this.

 

  • insert xref as a block using a different name. insert at '(0 0 0)
  • use nentsel to select the line in the block
  • use visual lisp to explode block
  • this will allow you to step though each item and pull points. example
  • delete exploded entity's as you go
  • delete inserted block
  • copy item to points in list.

 

Yes you're probably right although it seems like a lot of work, I was looking into the posts and found this that seems to be very helpful and as I see it follows your idea.

So I started learning about nested objects and nentsel and did this little code to start.

;;; Places a text on the start and end points of a line on a selected layer on an xrefered file or a block
;;; 20220215 By Isaac A.
(defun c:txrf ( / cept cspt ex ey matrix ndata otyp sx sy)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")

   (setvar "osmode" 37)
   (setq ndata (nentsel "\nPick a line on the target layer: "))
   (setq otyp (cdr (assoc 0 (entget (car ndata)))))
   (if (= otyp "LINE")
      (progn
        (setq cspt (assoc 10 (entget (car ndata)))
              cept (assoc 11 (entget (car ndata)))
              matrix (caddr ndata)
        )
        (setq sx (+
               (* (car (nth 0 matrix))(cadr cspt))     ; M00 * X
               (* (car (nth 1 matrix))(caddr cspt))    ; M10 * Y
               (* (car (nth 2 matrix))(cadddr cspt))   ; M20 * Z
               (car (nth 3 matrix))                    ; M30
           )
        )
        (setq sy (+
               (* (cadr (nth 0 matrix))(cadr cspt))    ; M01 * X
               (* (cadr (nth 1 matrix))(caddr cspt))   ; M11 * Y
               (* (cadr (nth 2 matrix))(cadddr cspt))  ; M21 * Z
               (car (nth 3 matrix))                    ; M31
           )
        )
        (setq ex (+
               (* (car (nth 0 matrix))(cadr cept))     ; M00 * X
               (* (car (nth 1 matrix))(caddr cept))    ; M10 * Y
               (* (car (nth 2 matrix))(cadddr cept))   ; M20 * Z
               (car (nth 3 matrix))                    ; M30
            )
        )
        (setq ey (+
               (* (cadr (nth 0 matrix))(cadr cept))    ; M01 * X
               (* (cadr (nth 1 matrix))(caddr cept))   ; M11 * Y
               (* (cadr (nth 2 matrix))(cadddr cept))  ; M21 * Z
               (car (nth 3 matrix))                    ; M31
            )
        )
        (entmake
            (list '(0   .  "TEXT")
                  '(100 .  "AcDbEntity")
                  '(100 .  "AcDbText")
                  (cons 10 (list sx sy 0.))		
                  (cons 40 0.3)			
                  (cons 1  (strcat "(" (rtos sx 2 3) "," (rtos sy 2 3) ")"))	
            )
        )
        (entmake
            (list '(0   .  "TEXT")
                  '(100 .  "AcDbEntity")
                  '(100 .  "AcDbText")
                  (cons 10 (list ex ey 0.))		
                  (cons 40 0.3)			
                  (cons 1  (strcat "(" (rtos ex 2 3) "," (rtos ey 2 3) ")"))	
            )
        )
      )
      (princ "\nThe object is not a line")
   ) 

   (vl-cmdf "_.undo" "_end")
   (princ)
)

 

exampl02.jpg

Edited by Isaac26a
Link to comment
Share on other sites

Can't figure out how to get the xref entity name if you use nentsel on the line (trying to only use one selecton). so you have to pick the xref and then the line after the block is inserted.

 

Never mind figured it out. Now you only need to select the line in the xref.

 

(defun C:C2L (/ SS BP xref path blk line lay blk-entities pts-lst)
  (setvar "cmdecho" 0)
  (vl-cmdf "_.undo" "_begin")
  (prompt "\nSelect the object(s) to copy. ")
  (setq SS (ssget)
        BP (getpoint "\nSelect Base Point: ")
        ent (entsel "\nSelect Line")
        xref (car ent)
        line-pt (cadr ent)              
        path (vla-get-path (vlax-ename->vla-object xref))
        path (findfile (strcat (vl-filename-base path) (vl-filename-extension path)))
  )
  (vl-cmdf "_Insert" (strcat "blk=" path) '(0 0 0) "" "" "")
  (setq blk (entlast)
        line (car (nentselp line-pt))
        lay (cdr (assoc 8 (entget line)))
        blk-entities (vlax-invoke (vlax-ename->vla-object blk) 'explode)
  )
  (foreach ent blk-entities
    (if (eq (vla-get-layer ent) lay)
      (setq pts-lst (cons (vlax-curve-getStartPoint ent) pts-lst)
            pts-lst (cons (vlax-curve-getendpoint ent) pts-lst)
      )
    )
    (vla-delete ent)
  )
  (entdel blk) ;prob a good idea to purge the block too.
  (foreach PT pts-lst
    (vl-cmdf "_.Copy" SS "" BP PT)
  )  
  (vl-cmdf "_.undo" "_end")
  (setvar "cmdecho" 1)
  (princ)
)

 

Edited by mhupp
forgot the undo end / cmdecho1
  • Like 1
Link to comment
Share on other sites

23 minutes ago, mhupp said:

Never mind figured it out. Now you only need to select the line in the xref.

Thank you it did worked well on your previous version, this one is better, it seems that there's still a long way for me to go to get proficient in lisp (but working on it). Thanks a lot.

  • Like 1
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...