XREF attach tool

Discussion in 'AutoCAD' started by Timofeev Yury, Aug 23, 2003.

  1. I have a text file with the list of DWG files which I must attach as XREFs
    to the master file with no scale and offset. Is there a tool or macro to do
    this? How can I do this in AutoLISP?

    Thanks.
    Yury
     
    Timofeev Yury, Aug 23, 2003
    #1
  2. Timofeev Yury

    bestafor Guest

    HiHo;
    From the AutoCad help file. And below a sub from George Head.
    Beware, there is a limit to
    amount of XDAT one may add.You can use extended data as a means for linking information with objects in
    a drawing. For more information on extended data, see "Extended Data--Xdata"
    in chapter 9 of the AutoCAD Customization Guide.
    The following example assigns extended data to the selected objects. (For
    information about the acadDoc object, see "
    Accessing the Drawing with the Document Object.")

    Dim sset As Object 'Define sset as a SelectionSet object

    'Set sset to a new selection set named SS1 (the name doesn't matter here)
    Set sset = acadDoc.SelectionSets.Add("SS1")
    sset.SelectOnScreen 'Prompt user to select objects

    'The following variable assignments define the xdata RegApp name and
    ' string values
    Dim appName, xdataStr As String
    appName = "MY_APP"
    xdataStr = "This is some xdata"

    'The following two variable definitions must be arrays of the same size.
    'The first variable holds integer values that define the types of the data
    'in the second variable. The first value (index 0) of one variable maps
    'to the same index of the other variable.
    Dim xdataType(0 To 1) As Integer 'Define xdataType for the data types
    Dim xdata(0 To 1) As Variant 'Define xdata for the data values

    'The following variable assignments define the values for each array.
    xdataType(0) = 1001 '1001 indicates the RegApp name
    xdata(0) = appName 'RegApp name string value
    xdataType(1) = 1000 '1000 indicates a string value
    xdata(1) = xdataStr 'Xdata string value

    'The following code loops through all entities in the selection set and
    'assigns the xdata to each entity
    Dim ent As Object
    For Each ent In sset 'For each entity in the selection set
    ent.SetXData xdataType, xdata 'assign the xdata

    Next ent

    The following example displays the xdata attached with the previous example.
    If you attach xdata other than strings (type 1000), you will need to revise
    this code.

    Dim sset As Object 'Define sset as a SelectionSet object
    'Set sset to a new selection set
    named SS1
    Set sset = acadDoc.SelectionSets.Add("SS1")
    sset.SelectOnScreen 'Prompt user to select objects
    Dim xdataType As Variant 'Define xdataType to receive xdata
    types
    Dim xdata As Variant 'Define xdata to receive xdata values

    Dim xd As Variant
    Dim ent As Object
    Dim xdi As Integer 'Define integer variable index
    counter
    xdi = 0 'Set xdi to 0, tracks index of xdata
    Dim msgstr, NL As String 'Declare string variables for
    messages
    NL = Chr(13) & Chr(10) 'Define newline
    Dim appName As String 'Declare string variable for RegApp
    name
    appName = "MY_APP" 'Define RegApp name to retrieve

    'Display message showing number of objects selected
    MsgBox Str(sset.Count) & " objects selected."
    For Each ent In sset 'Loop for each entity in selection
    set
    msgstr = "" 'Reset msgstr to a NULL string
    xdi = 0 'Reset the index counter

    'Retrieve the appName xdata type and value for the entity
    ent.GetXData appName, xdataType, xdata

    'If the xdataType variable is not initialized, there was no appName
    xdata
    'to retrieve for that entity
    If VarType(xdataType) <> vbEmpty Then
    For Each xd In xdata 'Loop for each xdata value
    msgstr = msgstr & NL & Str(xdataType(xdi)) & ": " & xd
    xdi = xdi + 1 'Increment the index counter
    Next xd 'Next xdata value
    End If

    'If the msgstr variable is NULL, there was no xdata
    If msgstr = "" Then msgstr = NL & "NONE"

    'Display a message reporting the xdata for that entity
    MsgBox appName & " xdata on " & ent.EntityName & ":" & NL & msgstr

    Next ent 'Next entity in selection set
    .............................................................................
    ...................
    ;
    ;And from
    ;from "AUTOLISP" by George Head
    ;called (eeadd value list)
    ;where value = Associated code list
    ; list = entity list
    ;it returns the new entity list for a (entmod)
    (defun eeadd (nl lst)
    (setq d (assoc -3 e))
    (setq d1 (car (cdr d)))
    (setq d2 (append d1 (list nl)))
    (setq d3 (subst d2 d1 d))
    (setq e1 (subst d3 d e))
     
    bestafor, Aug 23, 2003
    #2
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.