Select 3D solid to pass as parameter to IMPRINT command

Select 3D solid to pass as parameter to IMPRINT command

Anonymous
Not applicable
1,887 Views
17 Replies
Message 1 of 18

Select 3D solid to pass as parameter to IMPRINT command

Anonymous
Not applicable

Hi,

 

I have a solid on a layer and a line on another layer, how can i select the solid in lisp to pass it as parameter to the imprint function?

I already have the line in a variable, i just need to do the same thing with the solid. The solid is the only object in his layer.

 

Thanks for you help!

0 Likes
Accepted solutions (1)
1,888 Views
17 Replies
Replies (17)
Message 2 of 18

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

Hi,

 

I have a solid on a layer and a line on another layer, how can i select the solid in lisp to pass it as parameter to the imprint function?

I already have the line in a variable, i just need to do the same thing with the solid. The solid is the only object in his layer.

 

Thanks for you help!


Something like:


(setq solidSS (ssget "X" (list '(0 . "3DSOLID")(cons 8 "layerName")))) ; this will get you a selection set containing the solid (or: all on specified layer)

(setq c 0) ; counter

(foreach ent (entget (ssname solidSS c)) ; retrieve each entity in the list

   ; now you have the var ent containing 1 3D Solid entity you can pass to imprint

   ; Do your stuff here

   (setq c (1+ c)) ; up the counter

)

Message 3 of 18

Anonymous
Not applicable

Awesome! I would give it a try.

Stay tuned...

0 Likes
Message 4 of 18

Anonymous
Not applicable

Thanks again for your reply roland,

 

this being my first lisp routine i may need a little extra help. I realized that the line to imprint is not in a variable so i can't pass it to the imprint command.

Also being only one solid do we need to do the counter or we can simplify the code?

 

This is my current code with yours embedded towards the end:

 

(defun C:DAVIDE(/ var val p)
   (setq var '("Osmode" "Expert")
          val  (mapcar 'getvar var))
   (mapcar 'setvar var '(0 1))

;TURN OFF SOLID LAYER
    (command "-layer" "OFF" "IMAGINARY SURFACE" "" "")
      (princ)

;ENTER LAT, LON OF THE POINT OF INTEREST
         (command "geomarklatlong" PAUSE PAUSE " ")
         (princ)

;SELECT NODE JUST CREATED
         (setq p (cdr (assoc 10 (entget(ENTLAST)))))

;DRAW LINE 200 UNITS TALL ORTHO TO XY FROM NODE
          (command "line" p  (list (car p) (cadr p) (+ (caddr p) 200)) "")
    (mapcar 'setvar var val)
    (princ)

;TURN ON SOLID LAYER
    (command "-layer" "ON" "IMAGINARY SURFACE" "" "")

;IMPRINT LINE WITH SOLID
(setq solidSS (ssget "X" (list '(0 . "3DSOLID")(cons 8 "IMAGINARY SURFACE")))) ; this will get you a selection set containing the solid
(setq c 0) ; counter
(foreach ent (entget (ssname solidSS c)) ; retrieve each entity in the list
       ; now you have the var ent containing 1 3D Solid entity you can pass to imprint
       ; Do your stuff here
    (command "imprint" ???line_variable??? ent "YES") ; HERE IS WHERE I'M MISSING THE VARIABLE CONTAINING THE LINE
      (setq c (1+ c)) ; up the counter
)

;CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINT
;    (command "distance")

;SHOW DISTANCE
;    (alert "The distance is: ")
 
)
(princ)

0 Likes
Message 5 of 18

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

Thanks again for your reply roland,

 

this being my first lisp routine i may need a little extra help. I realized that the line to imprint is not in a variable so i can't pass it to the imprint command.

Also being only one solid do we need to do the counter or we can simplify the code?

 


Yes & no. The ssget will always return a selection set, which is a list of all entities selected, even if just 1.

The imprint function however expects a single entity, not a selection set. So, no you can't realy leave out the counter. (unless you are absolutely sure its always just one, or the first in the list)

 

...but, you can do it a different way, for example, by letting the user select the solid & line.

 

(command "_.imprint" PAUSE PAUSE) ; by far the easiest way

 

Or, just catch the newly created line in a variable and pass it to the imprint. (Note: the imprint command expects the solid first, the line second!)


 

(defun C:DAVIDE(/ var val p)
   (setq var '("Osmode" "Expert")
          val  (mapcar 'getvar var))
   (mapcar 'setvar var '(0 1))

;TURN OFF SOLID LAYER
    (command "-layer" "OFF" "IMAGINARY SURFACE" "" "")
      (princ)

;ENTER LAT, LON OF THE POINT OF INTEREST
         (command "geomarklatlong" PAUSE PAUSE " ")
         (princ)

;SELECT NODE JUST CREATED
         (setq p (cdr (assoc 10 (entget(ENTLAST)))))

;DRAW LINE 200 UNITS TALL ORTHO TO XY FROM NODE
          (command "line" p  (list (car p) (cadr p) (+ (caddr p) 200)) "")

          (setq linevar (entlast))
    (mapcar 'setvar var val)
    (princ)

;TURN ON SOLID LAYER
    (command "-layer" "ON" "IMAGINARY SURFACE" "" "")

;IMPRINT LINE WITH SOLID
(setq solidSS (ssget "X" (list '(0 . "3DSOLID")(cons 8 "IMAGINARY SURFACE")))) ; this will get you a selection set containing the solid
(setq c 0) ; counter
(foreach ent (entget (ssname solidSS c)) ; retrieve each entity in the list
       ; now you have the var ent containing 1 3D Solid entity you can pass to imprint
       ; Do your stuff here
    (command "imprint" ent linevar "YES") ; HERE IS WHERE I'M MISSING THE VARIABLE CONTAINING THE LINE
      (setq c (1+ c)) ; up the counter
)

;CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINT
;    (command "distance")

;SHOW DISTANCE
;    (alert "The distance is: ")
 
)
(princ)


This is my current code with yours embedded towards the end:

 

Message 6 of 18

Anonymous
Not applicable

Done as you said and switched the solid with the line but I'm getting an error on the imprint command.

Not sure if the problem is the line or the solid.

This is what it shows:

 

command: imprint

select a 3d solid or surface:

command: <entity name: FFB4BCD0>

0 Likes
Message 7 of 18

Anonymous
Not applicable

Do I have to declare linevar up on the first raw?

0 Likes
Message 8 of 18

roland.r71
Collaborator
Collaborator

it seems the entget is to much.

 

If i use

(setq ent (ssname solidSS c))

it accepts the input, for the solid.

...but it doesn't seem to accept a var for the second object. (to imprint)

 

Tried a few options but it either doesn't report anything (but stops before asking if the original should be deleted)

or it outputs: nil (& keeps asking for an object)

 

...but the variable is NOT nil...

 

I'll have to look into the imprint command to see whats wrong.

 

edit: i see. The second argument must be a selection set (strangly the function itself allows only for 1 object to be selected)

 

So:

use (setq linevar (ssget "_L")) instead of (setq linevar (entlast))

 

(setq linevar (ssget "_L")) ; Right after creating the line

(setq ent (ssname solidSS c)) ; Instead of (setq ent (entget (ssname solidSS c)))

&

(command "_.imprint" ent linevar "_Y" "") ; the extra "" is to close the function, otherwise it keeps going (restarts)

Message 9 of 18

roland.r71
Collaborator
Collaborator

it would be wise to declare the solidSS, ent & linevar as local, with the defun

 

(defun C:DAVIDE(/ var val p solidSS ent linevar)

 

...but this should be of no consequence to the lisps working (in this case)

 

edit: Woops, forgot about the selection set var. "solidSS"

Message 10 of 18

Anonymous
Not applicable

QUOTE:

edit: Woops, forgot about the selection set var. "solidSS"

 

What do i have to write exactly and where?

0 Likes
Message 11 of 18

roland.r71
Collaborator
Collaborator

At first i forgot to add the solidSS var to the function declaration, but i edited it.

 

What needs to be changed are the blue parts:

(defun C:DAVIDE(/ var val p solidSS ent linevar)
   (setq var '("Osmode" "Expert")
         val  (mapcar 'getvar var))
   (mapcar 'setvar var '(0 1))

; TURN OFF SOLID LAYER
    (command "-layer" "OFF" "IMAGINARY SURFACE" "" "")
      (princ)

; ENTER LAT, LON OF THE POINT OF INTEREST
         (command "geomarklatlong" PAUSE PAUSE " ")
         (princ)

; SELECT NODE JUST CREATED
         (setq p (cdr (assoc 10 (entget(ENTLAST)))))

; DRAW LINE 200 UNITS TALL ORTHO TO XY FROM NODE
          (command "line" p  (list (car p) (cadr p) (+ (caddr p) 200)) "")
          (setq linevar (ssget "_L"))
    (mapcar 'setvar var val)     (princ) ; TURN ON SOLID LAYER     (command "-layer" "ON" "IMAGINARY SURFACE" "" "") ; IMPRINT LINE WITH SOLID (setq solidSS (ssget "X" (list '(0 . "3DSOLID")(cons 8 "IMAGINARY SURFACE")))) ; this will get you a selection set containing the solid (setq c 0) ; counter (foreach ent (ssname solidSS c) ; retrieve each entity in the list
       ; now you have the var ent containing 1 3D Solid entity you can pass to imprint        ; Do your stuff here     (command "imprint" ent linevar "YES") ; HERE IS WHERE I'M MISSING THE VARIABLE CONTAINING THE LINE       (setq c (1+ c)) ; up the counter ) ; CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINT ;    (command "distance") ; SHOW DISTANCE ;    (alert "The distance is: ")   ) (princ)

 

 

Message 12 of 18

Anonymous
Not applicable

Thank you for your patience.

 

I'm getting:

command: ; error: bad argument type: cosp <entity name: 7ffffb4a980>

 

this is the code, did i miss anything?

 

(defun C:DAVIDE(/ var val p solidSS ent linevar)
   (setq var '("Osmode" "Expert")
         val  (mapcar 'getvar var))
   (mapcar 'setvar var '(0 1))

; TURN OFF SOLID LAYER
    (command "-layer" "OFF" "IMAGINARY SURFACE" "" "")
      (princ)

; ENTER LAT, LON OF THE POINT OF INTEREST
         (command "geomarklatlong" PAUSE PAUSE " ")
         (princ)

; SELECT NODE JUST CREATED
         (setq p (cdr (assoc 10 (entget(ENTLAST)))))

; DRAW LINE 200 UNITS TALL ORTHO TO XY FROM NODE
          (command "line" p  (list (car p) (cadr p) (+ (caddr p) 200)) "")
          (setq linevar (ssget "_L"))
    (mapcar 'setvar var val)
    (princ)

; TURN ON SOLID LAYER
    (command "-layer" "ON" "IMAGINARY SURFACE" "" "")

; IMPRINT LINE WITH SOLID
(setq solidSS (ssget "X" (list '(0 . "3DSOLID")(cons 8 "IMAGINARY SURFACE")))) ; this will get you a selection set containing the solid
(setq c 0) ; counter
(foreach ent (ssname solidSS c) ; retrieve each entity in the list
       ; now you have the var ent containing 1 3D Solid entity you can pass to imprint
(command "_.imprint" ent linevar "_Y" "")
      (setq c (1+ c)) ; up the counter
)

)
(princ)

0 Likes
Message 13 of 18

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

Thank you for your patience.

 

I'm getting:

command: ; error: bad argument type: cosp <entity name: 7ffffb4a980>

 

this is the code, did i miss anything?

 

-snip-



Could you post a sample dwg, with all the layers, a 3D solid & line to imprint?

So i can test it

Message 14 of 18

Anonymous
Not applicable

Here you go.

 

you can enter the following coordinates when running the lisp routine. You'll see it hiding the solid, creating the line, showing the solid again then the error when trying to imprint.

 

Lat: 37.397533

Lon:14.905701

0 Likes
Message 15 of 18

roland.r71
Collaborator
Collaborator
Accepted solution

It looks like i got it working, but...

I don't see any change...

 

The point is created

The line gets created

The solid gets selected and the imprint command looks to be working.

the line gets deleted.

 

...but i don't see any visual change after that.

(except for the added point/marker)

 

So please check if it does work as it should.

 

(defun C:DAVIDE(/ var val p solidSS ent linevar)

    (setq var '("Osmode" "Expert")
          val  (mapcar 'getvar var))
    (mapcar 'setvar var '(0 1))

; TURN OFF SOLID LAYER
    (command "_.-layer" "OFF" "IMAGINARY SURFACE" "" "")

; ENTER LAT, LON OF THE POINT OF INTEREST
;    (command "geomarklatlong" "37.397533" "14.905701" " ")
    (command "geomarklatlong" PAUSE PAUSE " ")

; SELECT NODE JUST CREATED
    (setq p (cdr (assoc 10 (entget(ENTLAST)))))

; DRAW LINE 200 UNITS TALL ORTHO TO XY FROM NODE
    (command "_.line" p (list (car p) (cadr p) (+ (caddr p) 200)) "")
    (setq linevar (ssget "_L"))
    (mapcar 'setvar var val)

; TURN ON SOLID LAYER
    (command "_.-layer" "ON" "IMAGINARY SURFACE" "")

; IMPRINT LINE WITH SOLID
    (setq solidSS (ssget "X" (list '(0 . "3DSOLID")(cons 8 "IMAGINARY SURFACE")))) ; this will get you a selection set containing the solid
    (setq ent (ssname solidSS 0)) ; retrieve first entity in the list (there should be only 1)
(command "_.imprint" ent linevar "_Y" "") ; CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINT ; (command "distance") ; SHOW DISTANCE ; (alert "The distance is: ")
(princ) ) (princ)
Message 16 of 18

Anonymous
Not applicable

It does work! Thanks!!!

 

All of this was to measure the height of the solid in the point chosen by the user.

Now i just need to measure the distance from the original point to the imprinted point.

I already have the original point in the variable p.

Do you have a quick code to select the imprinted point to pass to the distance command and show the distance to the user?

This will be it!

 

; SELECT IMPRINTED POINT
; ............

; CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINT ; (command "distance" p .........) ; SHOW DISTANCE ; (alert "The distance is: " ........)

 

0 Likes
Message 17 of 18

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

It does work! Thanks!!!

 

All of this was to measure the height of the solid in the point chosen by the user.

Now i just need to measure the distance from the original point to the imprinted point.

I already have the original point in the variable p.

Do you have a quick code to select the imprinted point to pass to the distance command and show the distance to the user?

This will be it!

 

; SELECT IMPRINTED POINT
; ............

; CALCULATE DISTANCE FROM ORIGINAL POINT TO THE IMPRINT ; (command "distance" p .........) ; SHOW DISTANCE ; (alert "The distance is: " ........)

 


No i don't.

Never worked with 3D solids this way, so its all new to me.

 

The challenge here is to get the coordinates for the imprinted point, which is a part of the 3D solid object.

...but i don't know how. (the imprint command doesn't return the coords, nor can it be retrieved by (entlast) as its not a new entity.

 

Selecting the solid is no problem, but how to retrieve the latest point added?

 

0 Likes
Message 18 of 18

Anonymous
Not applicable
Is there any other way to measure the distance from the original point to the solid?
0 Likes