DXF Codes 10 and 210 Formula

Discussion in 'AutoCAD' started by sheldonmcc, Sep 13, 2004.

  1. sheldonmcc

    sheldonmcc Guest

    I cannot belive that nobody has an answer for this question regarding DXF codes and WCS values (please do not refer me to the AutoCAD Help on this one since I'm working outside of AutoCAD and in VB6 creating DXF files).

    So far, all I have discovered is the OCS and WCS are different and they require translation. Since my application is outside of AutoCAD, the LISP function "TRANS" does not apply (or any other LISP function for that matter).

    I need a block to be inserted 45 degrees to the XY plane and down 45 from the XY plane in AutoCAD, but coming from a VB6 generated DXF file. While testing inside AutoCAD, the coordinate values using the LIST command for the block are different from the DXF values given for codes 10 and 210. In fact, they are not even close. My block has 2 known sets of start/end coordinates outside of AutoCAD (eg. a valve). Surely there must be a formula to calculate the 10 and 210 codes for a DXF file based on the 2 known sets of coordinates. The formula should work no matter what angle the block needs to be inserted at (even a simple insertion at 0 degrees at coordinates 0,0,0).

    If there are any brainiacs out there to tackle this month old problem for me, I promise to put you on my Christmas card list.

    I have researched the Arbitrary Axis Alogarithm but the documentation provided by AutoDesk provides no examples and is not very clear.

    Signed.....Confused in Calgary
     
    sheldonmcc, Sep 13, 2004
    #1
  2. sheldonmcc

    Doug Broad Guest

    Sheldon,
    You can't buy groceries with Christmas cards. ;-)

    You might have a slightly better chance of getting an answer if you post
    the question in the vba newsgroup. You're asking for something, however,
    that AutoCAD users take for granted and don't need to reinvent.

    Regards,
    Doug

    AutoCAD Help on this one since I'm working outside of AutoCAD and in VB6 creating DXF files).
    AutoCAD, the LISP function "TRANS" does not apply (or any other LISP function for that matter).
     
    Doug Broad, Sep 14, 2004
    #2
  3. sheldonmcc

    ifiew Guest

    sheldonmcc,
    I meet the same problem these days . I think the key of the solution is what dose OCS(Object Coordinate System) mean ? How does it be defined in AutoCAD ? If we know that we can find the formula .
    I'd like to tell you if I know . But I haven't known it yet . :p
    If you know ,please tell me .
    Thanks
    ifiew...from China ( So excuse me for my poor English :p )
     
    ifiew, Sep 14, 2004
    #3
  4. sheldonmcc

    ifiew Guest

    sheldonmcc
    I found this article about OCS . I think it's easy to tackle this problem now .
    Read the following words...
    Object Coordinate Systems (OCS)
    To save space in the drawing database (and in the DXF file), the points associated with each entity are expressed in terms of the entity’s own object coordinate system (OCS). With OCS, the only additional information needed to describe the entity’s position in 3D space are the 3D vector describing the Z axis of the OCS and the elevation value.
    For a given Z axis (or extrusion) direction, there are an infinite number of coordinate systems, defined by translating the origin in 3D space and by rotating the X and Y axes around the Z axis. However, for the same Z axis
    direction, there is only one OCS. It has the following properties:
    â–  Its origin coincides with the WCS origin.
    ■ The orientation of the X and Y axes within the XY plane is calculated in an arbitrary but consistent manner. AutoCAD performs this calculation using the arbitrary axis algorithm (see “Arbitrary Axis Algorithm†).
    For some entities, the OCS is equivalent to the WCS, and all points (DXF groups 10–37) are expressed in world coordinates. See the following table.

    Coordinate systems associated with an entity type
    Entities Notes
    3D entities such as line, point,
    3dface, 3D polyline, 3D vertex,
    3D mesh, 3D mesh vertex
    These entities do not lie in a particular plane. All points
    are expressed in world coordinates. Of these entities,
    only lines and points can be extruded. Their extrusion
    direction can differ from the world Z axis
    2D entities such as circle, arc,
    solid, trace, text, attrib, attdef,
    shape, insert, 2D polyline, 2D
    vertex, lwpolyline, hatch, image
    These entities are planar in nature. All points are
    expressed in object coordinates. These entities can be
    extruded. Their extrusion direction can differ from the
    world Z axis
    Dimension Some of a dimension’s points are expressed in WCS and some in OCS
    Viewport Expressed in world coordinates

    Once AutoCAD has established the OCS for a given entity, the OCS works as follows: The elevation value stored with an entity indicates how far to shift the XY plane along the Z axis (from the WCS origin) to make it coincide with the plane that contains the entity. How much of this is the user-defined
    elevation is unimportant.
    Any 2D points entered through the UCS are transformed into the corresponding 2D points in the OCS, which is shifted and rotated with respect to the UCS.

    These are a few ramifications of this process:
    â–  You cannot reliably find out what UCS was in effect when an entity was acquired.
    ■ When you enter the XY coordinates of an entity in a given UCS and then do a SAVEAS, you probably won’t recognize those XY coordinates in the DXF file. You must know the method by which AutoCAD calculates the X and Y axes in order to work with these values.
    â–  The elevation value stored with an entity and output in DXF files is a sum of the Z-coordinate difference between the UCS XY plane and the OCS XY plane, and the elevation value that the user specified at the time the entity was drawn.

    Arbitrary Axis Algorithm
    The arbitrary axis algorithm is used by AutoCAD internally to implement the arbitrary but consistent generation of object coordinate systems for all entities that use object coordinates.
    Given a unit-length vector to be used as the Z axis of a coordinate system,
    the arbitrary axis algorithm generates a corresponding X axis for the coordinate system. The Y axis follows by application of the right-hand rule.
    The method is to examine the given Z axis (also called the normal vector). If it is close to the positive or negative world Z axis, cross the world Y axis with the given Z axis to arrive at the arbitrary X axis. If it is not close, cross the world Z axis with the given Z axis to arrive at the arbitrary X axis. The boundary at which the decision is made was chosen to be both inexpensive to calculate and completely portable across machines. This is achieved by having a sort of “square†polar cap, the bounds of which are 1/64, which is
    precisely specifiable in six decimal-fraction digits and in six binary-fraction bits.
    The algorithm does the following (all vectors are assumed to be in 3D space and specified in the world coordinate system):

    Let the given normal vector be called N.
    Let the world Y axis be called Wy, which is always (0,1,0).
    Let the world Z axis be called Wz, which is always (0,0,1).

    Here we are looking for the arbitrary X and Y axes to go with the normal N.
    They will be called Ax and Ay. N could also be called Az (the arbitrary Z axis)
    as follows:

    If (abs (Nx) < 1/64) and (abs (Ny) < 1/64) then
    Ax = Wy X N (where “X†is the cross-product operator).
    Otherwise,
    Ax = Wz X N.
    Scale Ax to unit length.
    The method of getting the Ay vector is as follows:
    Ay = N X Ax. Scale Ay to unit length.
     
    ifiew, Sep 14, 2004
    #4
  5. sheldonmcc

    sheldonmcc Guest

    Doug,

    I am getting desparate with this problem and hiring someone to figure it out is a possibility.
     
    sheldonmcc, Sep 14, 2004
    #5
  6. sheldonmcc

    Gary D'Arcy Guest

    Confused in Calgary

    I'll bite what is an OCS?

    Regards Gary
    www.ltfactory.com


    codes and WCS values (please do not refer me to the AutoCAD Help on this one
    since I'm working outside of AutoCAD and in VB6 creating DXF files).
    require translation. Since my application is outside of AutoCAD, the LISP
    function "TRANS" does not apply (or any other LISP function for that
    matter).
    the XY plane in AutoCAD, but coming from a VB6 generated DXF file. While
    testing inside AutoCAD, the coordinate values using the LIST command for the
    block are different from the DXF values given for codes 10 and 210. In fact,
    they are not even close. My block has 2 known sets of start/end coordinates
    outside of AutoCAD (eg. a valve). Surely there must be a formula to
    calculate the 10 and 210 codes for a DXF file based on the 2 known sets of
    coordinates. The formula should work no matter what angle the block needs to
    be inserted at (even a simple insertion at 0 degrees at coordinates 0,0,0).
    me, I promise to put you on my Christmas card list.
    provided by AutoDesk provides no examples and is not very clear.
     
    Gary D'Arcy, Sep 14, 2004
    #6
  7. sheldonmcc

    DaveS Guest

    Object Coordinate System

    Have fun,
    Dave

     
    DaveS, Sep 14, 2004
    #7
  8. sheldonmcc

    Gary D'Arcy Guest

    Sorry Dave,

    You did not answer the question!
    What is an Object Coordinate System

    Regard Gary
    and yes I am.
     
    Gary D'Arcy, Sep 14, 2004
    #8
  9. sheldonmcc

    DaveS Guest

    It's the coordinate system the objects on. :O)

    Have fun,
    Dave

    PS: From help file\
    OCS

    Object Coordinate System-point values specified by certain methods and
    properties for the Polyline and LightweightPolyline objects are expressed in
    this coordinate system, relative to the object. These points are usually
    converted into the WCS, current UCS, or current DCS, according to the
    intended use of the object. Conversely, points in WCS, UCS, or DCS must be
    translated into an OCS before they are written to the database by means of
    the same properties. See the AutoCAD ActiveX and VBA Reference for the
    methods and properties that use this coordinate system.

    When converting coordinates to or from the OCS you must enter the normal for
    the OCS in the final argument of the TranslateCoordinates function
     
    DaveS, Sep 14, 2004
    #9
  10. sheldonmcc

    Doug Broad Guest

    Sheldon,
    You might try the vba newsgroup or the pn.classifieds newsgroup
    or the objectarx group.
    I'm not up to speed in VB yet so I wouldn't be your best choice.
    Tony Tanzillo, Byron Blattel or Frank Oquendo might be able to help.

    Good luck.



    possibility.
     
    Doug Broad, Sep 14, 2004
    #10
  11. sheldonmcc

    mataeux Guest

    i need some clarification

    i understand you are providing an insertion point in wcs.

    are you also giving two angles or another point?

    if you say " 45° in the xy plane " thats ok

    when you say " 45° FROM the xy plane " we need to know what axis of
    revolution or in what plane.

    to obtain the ocs and the 10 value you need to provide the 210 or normal

    if your application does any 3d rotating of blocks, you need covert rotation
    angles to a transformation matrix and apply the transformation to the 210
    value, use that to compute a new ocs, use that to compute a new 10 value and
    50 value


    codes and WCS values (please do not refer me to the AutoCAD Help on this one
    since I'm working outside of AutoCAD and in VB6 creating DXF files).
    require translation. Since my application is outside of AutoCAD, the LISP
    function "TRANS" does not apply (or any other LISP function for that
    matter).
    the XY plane in AutoCAD, but coming from a VB6 generated DXF file. While
    testing inside AutoCAD, the coordinate values using the LIST command for the
    block are different from the DXF values given for codes 10 and 210. In fact,
    they are not even close. My block has 2 known sets of start/end coordinates
    outside of AutoCAD (eg. a valve). Surely there must be a formula to
    calculate the 10 and 210 codes for a DXF file based on the 2 known sets of
    coordinates. The formula should work no matter what angle the block needs to
    be inserted at (even a simple insertion at 0 degrees at coordinates 0,0,0).
    me, I promise to put you on my Christmas card list.
    provided by AutoDesk provides no examples and is not very clear.
     
    mataeux, Sep 14, 2004
    #11
  12. We had this same style coordinate systems in shipbuilding. The software
    company worked with a local college (for them local) to create the 'Ship
    Coordinate System' which used a transformation matrix to calculate the
    actual locations for the objects. Sounds like Autodesk is taking steps
    towards this.

    I've never looked into it for AutoCAD but it's a good move for Autodesk and
    it continues the theory that started with 13 to move to a more database type
    dwg file. If it follows that trend we may see the AutoCAD main dwg info be
    part of a (semi-)central database. This also helps in some of the security
    issues people have been asking about concerning shipping dwg's to vendors.
    There would need to be another type of output that would be non- or semi-
    intelligent to send to those companies. Making our designs more secure.

    This could be where Autodesk is heading in their processes but without
    further details it's hard to tell... ;-) In any case, transformation
    matrixes are interesting for certain types of CAD work.

    If anyone is interested, I might be able to get some of my references out
    here. Let me know and I'll see what I have laying around.


    t
     
    cyberstrategist, Sep 14, 2004
    #12
  13. sheldonmcc

    mataeux Guest

    now that i read your previous thread's explanation:

    is it true that the first point is the origin of the block and the second
    point is along the x axis of the block ? if that is true, the block could
    spin about its own x axis at any angle, so you would need to provide that
    angle or decide, for example, that the block's z axis should always be in a
    plane with the wcs zaxis? then you would have enough info to compute first
    the 210, then the ocs, then the 10 and 50




    codes and WCS values (please do not refer me to the AutoCAD Help on this one
    since I'm working outside of AutoCAD and in VB6 creating DXF files).
    require translation. Since my application is outside of AutoCAD, the LISP
    function "TRANS" does not apply (or any other LISP function for that
    matter).
    the XY plane in AutoCAD, but coming from a VB6 generated DXF file. While
    testing inside AutoCAD, the coordinate values using the LIST command for the
    block are different from the DXF values given for codes 10 and 210. In fact,
    they are not even close. My block has 2 known sets of start/end coordinates
    outside of AutoCAD (eg. a valve). Surely there must be a formula to
    calculate the 10 and 210 codes for a DXF file based on the 2 known sets of
    coordinates. The formula should work no matter what angle the block needs to
    be inserted at (even a simple insertion at 0 degrees at coordinates 0,0,0).
    me, I promise to put you on my Christmas card list.
    provided by AutoDesk provides no examples and is not very clear.
     
    mataeux, Sep 14, 2004
    #13
  14. sheldonmcc

    sheldonmcc Guest

    I hope I can clarify this in words: "45 degrees from the XY plane" means it is rotated down. Example: draw a line from P1 (0,0,0) to P2 (10,10,-10). That is the direction my valve is inserted at. P1 & P2 are also the 2 known coordinates I have. Insert a block at those angles and DXF codes are not even close to the actual P1 & P2 given.

    Your absolutely correct on needing the 210 or normal. Converting rotation, etc. is what I need, but it is the formula at which this is done that I am missing. I have many answers regarding the Arbitrary Axis Alogorithm, but no examples. I find the documentation for how that works to be, well let's say *inadequate*.

    In my example of a valve being inserted at 45 degs and then down 45 degs, here are the coords reported by the list command:

    BLOCK REFERENCE Layer: "0"
    Space: Model space
    Color: 1 (red) Linetype: "BYLAYER"
    Handle = 2B843D
    "VALVE"
    at point, X= 0.000 Y= 0.000 Z= 0.000
    X scale factor 1.000
    Y scale factor 1.000
    Z scale factor 1.000
    Extrusion direction relative to UCS:
    X= 0.500 Y= 0.500 Z= 0.707

    Then with LISP, here are the DXF codes:

    ((-1 . <Entity name: 4048dc80>) (0 . "INSERT") (330 . <Entity
    name: 40085cf8>) (5 . "2B8430") (100 . "AcDbEntity") (67 . 0) (410 . "Model")
    (8 . "0") (62 . 1) (100 . "AcDbBlockReference") (2 . "VALVE") (10 5.82077e-011
    -1.29247e-026 2.32831e-010) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 4.71239) (70
    0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.5 0.5 0.707107))

    So, how does AutoCAD calculate the DXF 10 codes and 210 codes based on 2 sets of coordinates....EG P1 & P2?

    SM
     
    sheldonmcc, Sep 14, 2004
    #14
  15. sheldonmcc

    sheldonmcc Guest

    Yes, the first point is the origin of the block. For a valve, the first point is one side of the valve symbol and the 2nd point is the other side of the symbol. I will try the formula's from Luis as replied in this thread.

    thx
     
    sheldonmcc, Sep 14, 2004
    #15
  16. sheldonmcc

    mataeux Guest

    given p1 and p2, return the 10 50 and 210 dxf values of a block

    i can provide your solution. please verify:

    1. a line from p1 to p2 lies along the X axis of the block
    and
    2. the Z axis of the block lies in a plane with the z axis of the wcs
     
    mataeux, Sep 14, 2004
    #16
  17. sheldonmcc

    sheldonmcc Guest

    Yes, that is correct. Need more info? I know this is confusing without graphics.
     
    sheldonmcc, Sep 15, 2004
    #17
  18. sheldonmcc

    mataeux Guest

    ;;; she gets the job done

    (defun c:valve()

    (defun magnitude (vector)
    (sqrt (+ (expt(car vector)2) (expt(cadr vector)2) (expt(caddr
    vector)2) ) )
    )

    (defun unitVector (vector / mag)
    (setq mag (magnitude vector))
    (list (/(car vector)mag) (/(cadr vector)mag) (/(caddr vector)mag) )
    )

    (defun vectorCrossProduct (vector1 vector2)
    (list (- (*(cadr vector1)(caddr vector2)) (*(cadr vector2)(caddr
    vector1)) )
    (- (*(caddr vector1)(car vector2)) (*(caddr vector2)(car
    vector1)) )
    (- (*(car vector1)(cadr vector2)) (*(car vector2)(cadr
    vector1)) )
    )
    )

    (setq p1 (getpoint "\nany point in 3D space: ")
    p2 (getpoint "\nsecond point in 3D space: ")

    axisXblk (mapcar '- p2 p1)

    axisYblk (list (-(cadr axisXblk)) (car axisXblk) 0)

    axisZarb (unitVector(vectorCrossProduct axisXblk
    axisYblk))

    is_close (and (< (abs(car axisZarb)) 0.015625) (< (abs(cadr
    axisZarb)) 0.015625) )

    axisXarb (unitVector(vectorCrossProduct (if is_close '(0 1 0)'(0 0
    1)) axisZarb))

    axisYarb (unitVector(vectorCrossProduct axisZarb
    axisXarb))

    inspoint (list
    (+(*(car axisXarb)(car p1))
    (*(cadr axisXarb)(cadr p1))
    (*(caddr axisXarb)(caddr p1))
    )
    (+(*(car axisYarb)(car p1))
    (*(cadr axisYarb)(cadr p1))
    (*(caddr axisYarb)(caddr p1))
    )
    (+(*(car axisZarb)(car p1))
    (*(cadr axisZarb)(cadr p1))
    (*(caddr axisZarb)(caddr p1))
    )
    )

    rotation (list
    (+(*(car axisXarb)(car axisXblk))
    (*(cadr axisXarb)(cadr axisXblk))
    (*(caddr axisXarb)(caddr axisXblk))
    )
    (+(*(car axisYarb)(car axisXblk))
    (*(cadr axisYarb)(cadr axisXblk))
    (*(caddr axisYarb)(caddr axisXblk))
    )
    (+(*(car axisZarb)(car axisXblk))
    (*(cadr axisZarb)(cadr axisXblk))
    (*(caddr axisZarb)(caddr axisXblk))
    )
    )

    rotation (if(=(car rotation)0)
    (* pi (if(<(cadr rotation)0)-0.5 0.5))
    (+ (atan(/(cadr rotation)(car rotation))) (if (<(car
    rotation)0) pi 0))
    )

    )

    (entmake '((0 . "BLOCK")(2 . "VALVE")(70 . 0)(10 0 0 0)))
    (foreach l'(((0 -0.5)(0 0.5))((0 0.5)(1 -0.5))((1 -0.5)(1 0.5))((1
    0.5)(0 -0.5)))
    (entmake(list'(0 . "LINE")(cons 10(car l))(cons 11(cadr l))))
    )
    (entmake '((0 . "ENDBLK")))

    (entmake
    (list
    (cons 0 "INSERT")
    (cons 2 "VALVE")
    (cons 10 inspoint)
    (cons 41 (magnitude axisXblk))
    (cons 50 rotation)
    (cons 210 axisZarb)
    )
    )

    )
     
    mataeux, Sep 16, 2004
    #18
  19. sheldonmcc

    sheldonmcc Guest

    I just have to convert it into VB code to work outside of AutoCAD....thanks so much ;-)
     
    sheldonmcc, Sep 17, 2004
    #19
  20. sheldonmcc

    ifiew Guest

    sheldonmcc ,
    I've worked out my problem . Maybe It is useful to you .
    I post my solution following . If you have some questions ,you can read the artical I posted days before in this topic.

    Re: How to trans WCS to OCS ?
    I've got it . :)
    For example:
    0
    CIRCLE
    5
    93
    100
    AcDbEntity
    8
    0
    100
    AcDbCircle
    10
    -2.895377203008716
    20
    22.18318099539349
    30
    54.07639973511205
    40
    4.513139999999999
    210
    0.1433730436417575
    220
    -0.2456260747668 692
    230
    0.9587032918226155
    The center Point value (-2.895377203008716,22.18318099539349,54.07639973511205)is in OCS .
    The value in WCS is:(-0.467296,-6.54411,58.1523)
    When I know the circle center in WCS , and I want to write it in a *.dxf file , I must know the value in OCS .
    First : Calculate the OCS .
    We know the x , y , z axis in WCS is:
    Wx (1,0,0) Wy (0,1,0) Wz (0,0,1)
    The origin of the OCS and WCS is the same .
    The z axis of OCS is the value of the "210 " "220" "230"
    We always call it N , Here we are looking for the arbitrary X and Y axes to go with the normal N . They will be called Ax and Ay. N could also be called Az (the Z axis of OCS) .
    N (0.1433730436417575,-0.2456260747668692,0.9587032918226155)

    We calculate Ax first .
    if ( |Nx| < (1/64) && |Ny| < (1/64) )
    Ax = Wy × N (where “׆is the cross-product operator).
    else
    Ax = Wz × N

    Scale Ax to unit length.
    I got Ax (0.86364,0.50411,0) .

    The method of getting the Ay vector is as follows:
    Ay = N × Ax. Scale Ay to unit length.
    I got Ay (-0.483867,0.827974,0.28449422547) .

    So , the OCS matrix is
    matrixO :
    Axi Ayi Ni
    Axj Ayj Nj
    Axk Ayk Nk

    The center Point value in WCS is
    matrix1 : [x0,y0,z0]

    The value in OCS is matrix1*matrixO
    Axi Ayi Ni
    [ x0 y0 z0 ] × Axj Ayj Nj = [ x y z ]
    Axk Ayk Nk

    The result is the value in OCS ,also is the value below "10" "20" "30" in the dxf files.

    In this example:
    x0 = -0.467296
    y0 = -6.54411
    z0 = 58.1523
    and
    x = -2.895377203008716
    y = 22.18318099539349
    z = 54.07639973511205

    So the key is got the OCS matrix . :p
     
    ifiew, Sep 18, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.