Jump to content

Recommended Posts

Posted

Hi,

 

Can anyone here give me a heads up why this routine works perfectly in 2009, but not at all in 2010.

 

Description of function:

 

From a givev number of rows and columns, autocad places evenly any entity over a given space

 

Bare with me, this is one of my first compilations so it's fairly crude. Any points for improving is more than welcome!

 

(defun c:APLAC (/ oldcmd ss r1 c1 rc pt1 pt2 pt3 basepoint xbase ybase rad deg inspt inspt2)
 (setq oldcmd (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (princ "-----Space evenly-----")
 (setq aa (getstring "\n Perpendicular space / Twisted Space <T> "))
 (setq r1 (getint "\n Number of rows: "))
 (setq c1 (getint "\n Number of columns: "))
 (setq rc (+ c1 r1))
 (if (= aa "") ; Perpendicular space
   (progn
     (setq pt1 (getpoint "\n Upper left corner: "))
     (setq pt3 (getcorner pt1 "\n Lower right corner"))
     (setq pt2 (list (car pt1) (cadr pt3) 0))
   )
   (progn ; Twisted space
     (setq pt1 (getpoint "\n Upper left corner: "))
     (princ "\n Lower left corner: ")
     (command "_.line" pt1 pause "")
     (setq pt2 (getvar "lastpoint"))
     (command "_.erase" pt1 "")
     (princ "\n Lower right corner: ")
     (command "_.line" pt2 pause "")
     (setq pt3 (getvar "lastpoint"))
     (command "_.erase" pt2 "")
   )
  )
 (setq xbase (/ (distance pt3 pt2) (* c1 2))) ; X-coord for array
 (setq ybase (/ (distance pt1 pt2) (* r1 2))) ; Y-coord for array
 (setq rad (angle pt2 pt3)) ; Angle for twisted space
 (setq deg (* 180.0 (/ rad pi))) ; Angle in degree for twisted space
 (setq basepoint(list (+ (car pt2) xbase) (+ (cadr pt2) ybase) 0)) ; Coordinate for array
  (while (= ss nil) ; Chose symbol
    (setq ss(entsel))
  )
 (setq inspt(cdr(assoc 10 (entget (car ss))))) ; Insertion point for chosen symbol
 (command "_copy" ss "" inspt basepoint)
 (command "_rotate" (ssget "L") "" pt2 deg)
 (setq inspt2(cdr(assoc 10 (entget (ssname (ssget "L") 0))))) ; Insertion point for symbol in array
 (command "rotate" (ssget "L") "" inspt2 pause) ; Rotates symbol before array
 (if (> rc 2) ; Array only if the sum of rows and colums is larger than2
   (progn
   (command "ucs" "3" pt2 pt3 pt1)
   (cond ((= r1 1) ; Array at row=1
     (progn
      (command "_.array" (ssget "L") "" "R" r1 c1 (/ (distance pt3 pt2) c1) )
     )
     )
     ((= c1 1) ; Array at column=1
     (progn
      (command "_.array" (ssget "L") "" "R" r1 c1 (/ (distance pt1 pt2) r1))
     )
     )
     ( ; Array for any combination of rows and columns
     (progn
      (command "_.array" (ssget "L") "" "R" r1 c1 (/ (distance pt1 pt2) r1) (/ (distance pt3 pt2) c1) )
     ) 
     )
   ) ;end cond
   (command "_.ucs" "w")
   ) ;end progn
 ) ;end if
 (setvar "cmdecho" oldcmd)
 (princ)
) ; end defun

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    9

  • dhl

    7

  • Tharwat

    3

  • ReMark

    2

Top Posters In This Topic

Posted

I tried it with my version Cad 2010 and it's worked normally.

 

What is the error message that you receive when you run these codes ?

 

Some commands need to be standard .

 

Tharwat

Posted

I can confirm the above statement. Just tried out your lisp routine using 2010 on my home computer and it worked.

Posted

I see. Thanks for the quick response!

 

It seems to work perfectly with simple autocad entities such as circle, or whatever.

 

However, I use Autocad Mep and was able to use it with Mep devices in 2009, while not in 2010.

 

What I can see, it seems as the DXF code structuce has changed from 2009 to 2010, and the command to collect insertion points for devices is not the same. Checkinh the DXF entries for a device does not even include an insertion point anymore, but where do I find the insertion point?

Posted

FYI, getpoint can take more than one argument... save you drawing/erasing those lines...

Posted

So you use this routine to insert DXFs? Could you give us an example of a MEP device? I am unfamiliar with that terminology.

Posted
So you use this routine to insert DXFs? Could you give us an example of a MEP device? I am unfamiliar with that terminology.

 

He is referring to DXF Group Codes :) Not DXF Files...

Posted
What I can see, it seems as the DXF code structuce has changed from 2009 to 2010, and the command to collect insertion points for devices is not the same. Checkinh the DXF entries for a device does not even include an insertion point anymore, but where do I find the insertion point?

 

What objects are you querying the insertion point of?

Posted

a Mep Electrical Device, I tried to attach a dwg including an example object, but there's a limit of 250kb....

Posted
a Mep Electrical Device, I tried to attach a dwg including an example object, but there's a limit of 250kb....

 

I don't have MEP so it wouldn't help anyway - have you queried the entget data of the entity to determine the possible candidates for the DXF code of the insertion point, or is the information not displayed?

 

Also, perhaps this could be approached using VL, so maybe make a dump of the object to see what you can see :)

Posted

In 2009, the dxf code 10 contained the insertion point.

 

In 2010 it seems as it's hidden somehow. The DXF output for a mep device is as follows:

 

(-1 . <Entity name: 7ffff851c10>)
(0 . "AECB_DEVICE")
(330 . <Entity name: 7ffff8039f0>)
(5 . "1E5E1")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "E-63F--IE-N")

 

In 2009, this was miles long

Posted

Using the link, and the dump lisp routine returns insertion point under "location"

 

The question now is how do I extract "location"?

 

Very much a beginner when it comes to VL

 

Command: dump
 >>  Select Object  >> ; IAecbDevice: Device entity
; Property values:
;   AlternateName (RO) = "28W"
;   Application (RO) = #<VLA-OBJECT IAcadApplication 0000000140b98ca0>
;   BoundSpaces = 1
;   Connectors (RO) = #<VLA-OBJECT IAecbConnectors 0000000032d59ba0>
;   Description = ""
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000000000e1cbde0>
;   Elevation = 0.0
;   EngineeringData (RO) = #<VLA-OBJECT IAecbPartDataVariables 0000000032d59c30>
;   EngineeringID = ""
;   GUID (RO) = ""
;   Handle (RO) = "1E5E1"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 0000000032c86a28>
;   ID = ""
;   InsulationThickness = 0.0
;   Layer = "E-63F--IE-N"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   LiningThickness = 0.0
;   Load (RO) = "0"
;   Location = (286861.0 305315.0 0.0)
;   LockSize = 0
;   Material = "ByLayer"
;   MaximumSize = ...Indexed contents not shown...
;   Name (RO) = "28W"
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 42
;   ObjectID32 (RO) = 42
;   ObjectName (RO) = "AecbDbDevice"
;   OwnerID (RO) = 43
;   OwnerID32 (RO) = 43
;   PartDescription (RO) = "28W"
;   PlotStyleName = "ByLayer"
;   Rotation = 6.10144
;   ShadowDisplay = 0
;   SizeName (RO) = "28W"
;   Style = #<VLA-OBJECT IAecbDeviceStyle 000000002ec963e0>
;   StyleName = "28W"
;   SubType (RO) = ""
;   System = #<VLA-OBJECT IAecbElecSystemDef 000000002ec96280>
;   SystemAbbreviation (RO) = ""
;   SystemFamily (RO) = ""
;   SystemName = "Standard"
;   SystemType (RO) = 100
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 0000000032c896c0>
;   Type (RO) = "Lighting"
;   Visible = -1
;   Voltage (RO) = Exception occurred
; Methods supported:
;   ArrayPolar (3)
;   ArrayRectangular (6)
;   AttachAnchor (1)
;   ClosestNode (1)
;   Copy ()
;   Delete ()
;   GetAnchor ()
;   GetBoundingBox (2)
;   GetExtensionDictionary ()
;   GetXData (3)
;   Highlight (1)
;   IntersectWith (2)
;   Mirror (2)
;   Mirror3D (3)
;   Move (2)
;   NodeLocation (1)
;   ReleaseAnchor ()
;   Rotate (2)
;   Rotate3D (3)
;   ScaleEntity (2)
;   SetXData (2)
;   TransformBy (1)
;   Update ()

Posted

Use this on the entity name:

 

(vlax-get (vlax-ename->vla-object [color=red]<entityname>[/color]) 'Location)

Posted
Use this on the entity name:

 

(vlax-get (vlax-ename->vla-object [color=red]<entityname>[/color]) 'Location)

 

I tried it, but it does not get the Location of the entity .it returns an error as the following.

; error: ActiveX Server returned the error: unknown name: "LOCATION"

 

So if the Location means the start point of an entity , I think we could replace it with the following.

 

(vl-load-com)
(setq e (car (entsel "\nSelect something :")))
(vlax-get (vlax-ename->vla-object e) 'startpoint)

 

What you think ?

 

Tharwat

Posted
I tried it, but it does not get the Location of the entity .it returns an error as the following.

 

But are you using MEP?

 

So if the Location means the start point of an entity, I think we could replace it with the following.

 

Did query the object for the StartPoint property, or is that a guess?

Posted

It's not a guess. it's just a discussion .

 

If you got angry with it that far, just ignore it.

Posted
Use this on the entity name:

 

(vlax-get (vlax-ename->vla-object [color=red]<entityname>[/color]) 'Location)

 

Thanks! This works like a charm.

 

Being a beginner at VL, would you mind terribly walking through your code, and perhaps you have an explanation why non VL command don't return the same output?

Posted
It's not a guess. it's just a discussion .

 

If you got angry with it that far, just ignore it.

 

Angry? Who's getting angry?

Posted
Thanks! This works like a charm.

 

Excellent :)

 

Being a beginner at VL, would you mind terribly walking through your code, and perhaps you have an explanation why non VL command don't return the same output?

 

Before we can deal with any VL properties/methods we must first convert the entity name to a VLA-Object, for this we use vlax-ename->vla-object.

 

When we have the VLA-Object, we can query its properties, and use its methods.

 

See here for a more complete explanation of the ActiveX Object Model:

http://www.cadtutor.net/forum/showthread.php?53374-xref-clip-boundry&p=361940&viewfull=1#post361940

 

Excellent :)

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