Jump to content

Recommended Posts

Posted (edited)

I am doing a little playing around and studying

 

I want to know if I can shorten my code by placing (3) entities in one variable and then using one entmake to create all my entities.

 

 

In my code below I (setq obj1, obj2 and obj3) then I (entmake obj1, obj2 and obj3)

 

What I want to know is can I use one (setq obj) to hold all 3 entities, then use one (entmake obj) to create all the object at once.

 

Thanks

 

 

Forgot to add my code:

 

 

 

 
(defun C:test ()
(setq pt1 (getpoint "\nSelect First Point"))
(setq pt2 (getpoint "\nSelect Second Point"))
(setq pt3 (list (car pt2) (cadr pt1)))
(setq pt4 (list (car pt1) (cadr pt2)))
(setq obj1 (list
(cons 0 "lwpolyline")
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 8 "0")
(cons 43 0)
(cons 90 5)
(cons 70 1)
(cons 10 pt1)
(cons 10 pt3)
(cons 10 pt2)
(cons 10 pt4)
)
)

(setq obj2 (list
(cons 0 "line")
(cons 100 "AcDbEntity")
(cons 100 "AcDbLine")
(cons 8 "0")
(cons 10 pt1)
(cons 11 pt2)
)
)

(setq obj3 (list
(cons 0 "line")
(cons 100 "AcDbEntity")
(cons 100 "AcDbLine")
(cons 8 "0")
(cons 10 pt3)
(cons 11 pt4)
)
)

(entmake obj1)
(entmake obj2)
(entmake obj3)


(princ)
)

Edited by cadman6735
Posted

You will have to have at least 2 entities, since you can't make an X within a box without crossing over at least once. If you don't care about that, then you can easily create everything as one LWPolyline. You can do a lot of scaling down, through.

Posted
You will have to have at least 2 entities, since you can't make an X within a box without crossing over at least once. If you don't care about that, then you can easily create everything as one LWPolyline. You can do a lot of scaling down, through.

 

Hey Alan

 

Thanks for the reply

 

I understand your point about creating it with LWPolyline, but my main interest is not the object or the shape but can I chain (entmake) to create multiple objects under one (entmake) or store multiple objects under one variable.

 

The beginning of your reply

You will have to have at least 2 entities, since you can't make an X within a box without crossing over at least once
tells me that I can not. Each entity will have to have its own variable

 

 

What I was thinking was something looking like this"

 

 
(setq obj (list
      (cons 0 "lwpolyline")
      (cons 100 "AcDbEntity")
      (cons 100 "AcDbPolyline")
      (cons 8 "0")
      (cons 43 0)
      (cons 90 5)
      (cons 70 1)
      (cons 10 pt1)
      (cons 10 pt3)
      (cons 10 pt2)
      (cons 10 pt4)

    (list
      (cons 0 "line")
      (cons 100 "AcDbEntity")
      (cons 100 "AcDbLine")
      (cons 8 "0")
      (cons 10 pt1)
      (cons 11 pt2)

(entmake obj)
    )
 )

 

Or something like this with my first code.

 

(entmake obj1 obj2 obj3)

Posted

entmake/entmakex/entmod works with only one entity at a time.

Posted

Instead of defining each as a list, just entmake from there. Also, LOCALIZE YOUR VARIABLES!!

Posted
Instead of defining each as a list, just entmake from there. Also, LOCALIZE YOUR VARIABLES!!

 

Cool, thanks entmake/entmakex/entmod only work one at a time (is there a function that does what I am asking???) allows me to work on multiple elements under one variable?

 

I am of the impression that not localizing variables is a peev. I still don't have the concept of localized variables yet. ( I understand what it is suppose to do, clear the variable out of memory) but it doesnt seem to work for me.

 

When I localize and run a LSP routine then after it is finished I will !obj1 and it will return the stored info. So I am confussed on how it is suppose to work.

 

But I usally do localize my variables just to follow suit in what I read to learn good practaces but didn't here because I am playing but will from now on out of curtisy.

 

 

 

Another question

 

you are saying instead of defining a list, just entmake...

 

do mean instead of defining a (setq) just use entmake?

 

Because even entmake requires a list ( I believe, as my understanding takes me so far)

 

 
(entmake (list
      (cons 0 "lwpolyline")
      (cons 100 "AcDbEntity")
      (cons 100 "AcDbPolyline")
      (cons 8 "0")
      (cons 43 0)
      (cons 90 5)
      (cons 70 1)
      (cons 10 pt1)
      (cons 10 pt3)
      (cons 10 pt2)
      (cons 10 pt4)
))

 

Thanks

Posted

There is nothing that can create multiple objects, unless you count blocks, but that's still on one object (just has multiple nested objects). You can use mapcar 'entmake (list obj1 obj2 obj3), but I would just stick with (entmake (list (cons 0 "LINE) blah blah blah).

 

As far as localizing variables, it is best practice because you don't want something from one routine to mess with the same one or a different routine.

Adding items to a list is a perfect example:

 

(defun c:Test1 (/)
 (repeat 3
   (setq val (getreal "\nSpecify number: "))
   (setq lst (cons val lst))
 )
 (print lst)
 (princ)
)

 

eg.

Command: test1

Specify number: 1

Specify number: 2

Specify number: 3

(3.0 2.0 1.0)

Command:
Command: !lst
(3.0 2.0 1.0)

Command: test1

Specify number: 4

Specify number: 5

Specify number: 6

(6.0 5.0 4.0 3.0 2.0 1.0)

See what happens after I execute the routine a second time. All I wanted was a list of 4 5 6, but I received 1-6 because I didn't localize my variable.

Posted

Thanks Alan

 

Now, I am curiouse of mapcar and will play with this to see how it works.

 

Thanks for your help and the advice

Posted
I am doing a little playing around and studying

 

I want to know if I can shorten my code by placing (3) entities in one variable and then using one entmake to create all my entities.

 

 

In my code below I (setq obj1, obj2 and obj3) then I (entmake obj1, obj2 and obj3)

 

What I want to know is can I use one (setq obj) to hold all 3 entities, then use one (entmake obj) to create all the object at once.

 

Thanks

 

 

Forgot to add my code:

 

 

 

 
(defun C:test ()
(setq pt1 (getpoint "\nSelect First Point"))
(setq pt2 (getpoint "\nSelect Second Point"))
(setq pt3 (list (car pt2) (cadr pt1)))
(setq pt4 (list (car pt1) (cadr pt2)))
(setq obj1 (list
(cons 0 "lwpolyline")
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 8 "0")
(cons 43 0)
(cons 90 5)
(cons 70 1)
(cons 10 pt1)
(cons 10 pt3)
(cons 10 pt2)
(cons 10 pt4)
)
)

(setq obj2 (list
(cons 0 "line")
(cons 100 "AcDbEntity")
(cons 100 "AcDbLine")
(cons 8 "0")
(cons 10 pt1)
(cons 11 pt2)
)
)

(setq obj3 (list
(cons 0 "line")
(cons 100 "AcDbEntity")
(cons 100 "AcDbLine")
(cons 8 "0")
(cons 10 pt3)
(cons 11 pt4)
)
)

(entmake obj1)
(entmake obj2)
(entmake obj3)


(princ)
)

 

 

This works, But will need some polishing.

I will leave that up to you.

 

(defun C:test ()
 (setq pt1 (getpoint "\nSelect First Point"))
 (setq pt2 (getpoint "\nSelect Second Point"))
 (setq pt3 (list (car pt2) (cadr pt1)))
 (setq pt4 (list (car pt1) (cadr pt2)))
 (entmake
   (list
     (cons 0 "lwpolyline")
     (cons 100 "AcDbEntity")
     (cons 100 "AcDbPolyline")
     (cons 8 "0")
     (cons 43 0)
     (cons 90 4)
     (cons 70 1)
     (cons 10 pt1)
     (cons 10 pt3)
     (cons 10 pt2)
     (cons 10 pt4)))
 (entmake
   (list
     (cons 0 "line")
     (cons 100 "AcDbEntity")
     (cons 100 "AcDbLine")
     (cons 8 "0")
     (cons 10 pt1)
     (cons 11 pt2)))
 (entmake
   (list
     (cons 0 "line")
     (cons 100 "AcDbEntity")
     (cons 100 "AcDbLine")
     (cons 8 "0")
     (cons 10 pt3)
     (cons 11 pt4)))
 (princ))

Posted
(defun c:XBox (/ foo p1 p3 p2 p4)
 ;; Alan J. Thompson, 07.22.10
 (defun foo (p)
   (if p
     (reverse (cdr (reverse (trans p 1 0))))
   )
 )

 (if (and (setq p1 (foo (getpoint "\nSpecify first corner: ")))
          (setq p3 (foo (getcorner (trans p1 0 1) "\nSpecify opposite corner: ")))
     )
   (progn
     (entmake
       (append
         (list (cons 0 "LWPOLYLINE")
               (cons 100 "AcDbEntity")
               (cons 100 "AcDbPolyline")
               (cons 90 4)
               (cons 70 1)
         )
         (mapcar
           (function (lambda (x) (cons 10 x)))
           (list p1 (setq p2 (list (car p3) (cadr p1))) p3 (setq p4 (list (car p1) (cadr p3))))
         )
       )
     )
     (mapcar (function (lambda (a b) (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 b)))))
             (list p1 p2)
             (list p3 p4)
     )
   )
 )
 (princ)
)

Posted
(defun c:XBox (/ foo p1 p3 p2 p4)
;; Alan J. Thompson, 07.22.10
(defun foo (p)
(if p
(reverse (cdr (reverse (trans p 1 0))))
)
)

(if (and (setq p1 (foo (getpoint "\nSpecify first corner: ")))
(setq p3 (foo (getcorner (trans p1 0 1) "\nSpecify opposite corner: ")))
)
(progn
(entmake
(append
(list (cons 0 "LWPOLYLINE")
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 90 4)
(cons 70 1)
)
(mapcar
(function (lambda (x) (cons 10 x)))
(list p1 (setq p2 (list (car p3) (cadr p1))) p3 (setq p4 (list (car p1) (cadr p3))))
)
)
)
(mapcar (function (lambda (a b) (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 b)))))
(list p1 p2)
(list p3 p4)
)
)
)
(princ)
)

 

Looks like that AutoCAD Magician with the cool beard is back.

Posted
Looks like that AutoCAD Magician with the cool beard is back.

HaHa

On a side note, I was playing in a tournament at the local card shop and while everyone was outside, in between rounds, this guy tells me he'd kill for a beard like mine.

Posted (edited)
HaHa

On a side note, I was playing in a tournament at the local card shop and while everyone was outside, in between rounds, this guy tells me he'd kill for a beard like mine.

Make sure you do not fall asleep anywhere near that guy or you will wake up to an Aqua Velva commercial.

 

You better hope it wasn't that Dutch guy from Aruba.

Was his name Joran Van Der Sloot by some chance?

Edited by The Buzzard

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