[SS3] [VBA} Macro to add models

Good evening,

in the attacched file I created several models. Some of them have as name a number. As you can see those one are 42.

I created them "manually", copying the model, renaming it and moving the content (in x and y).

I wish to reach number 250, but doing it manually would cost a lot of time.

Is it possible do it with a macro? If yes could you please suggest me the way or share some code to help me?

I tried to record a macro without having useful help.

Thanks a lot,

P

smartSketch.dgn

Parents
  • Workflow, how it can be solved when moved will be references attachments in Default model, not content in individual models:

    Prerequisities:

    • Default model exists
    • Template model (with proper content + attached references) exists, the content is ideally located at 0,0.
    • Known formula how x,y can be calculated, where <model number> is input.

    Step1: Generate models (VBA)

    CadInputQueue.SendKeyin "model active default"
    
    Dim source As ModelReference
    Set source = ActiveDesignFile.Models("Template")
    
    Dim index As Integer
    
    For index = 1 To 300
        Dim model As ModelReference
        Set model = ActiveDesignFile.Models.Copy(source, CStr(index))
        DoEvents
    Next index
    
    DoEvents

    Step 2: Attach references and move (pseudocode)

    CadInputQueue.SendKeyin "model active default"
    
    For index = 1 To 300
        attach reference "index"
        calculate X = f(index)
        calculate Y = f(index)
        move reference by x,y
    Next index

    Regards,

      Jan

Reply
  • Workflow, how it can be solved when moved will be references attachments in Default model, not content in individual models:

    Prerequisities:

    • Default model exists
    • Template model (with proper content + attached references) exists, the content is ideally located at 0,0.
    • Known formula how x,y can be calculated, where <model number> is input.

    Step1: Generate models (VBA)

    CadInputQueue.SendKeyin "model active default"
    
    Dim source As ModelReference
    Set source = ActiveDesignFile.Models("Template")
    
    Dim index As Integer
    
    For index = 1 To 300
        Dim model As ModelReference
        Set model = ActiveDesignFile.Models.Copy(source, CStr(index))
        DoEvents
    Next index
    
    DoEvents

    Step 2: Attach references and move (pseudocode)

    CadInputQueue.SendKeyin "model active default"
    
    For index = 1 To 300
        attach reference "index"
        calculate X = f(index)
        calculate Y = f(index)
        move reference by x,y
    Next index

    Regards,

      Jan

Children
  • Ok, thanks a lot Jan.

    I transformed your code as follow:

    Sub AddModels()
        Dim source As ModelReference
        Dim i As Integer
        Dim ModelToBeCopied As Integer
        
        CadInputQueue.SendKeyin "model active default"
         
        For i = 41 To 50
            Dim model As ModelReference
            ModelToBeCopied = i - 10
            Set source = ActiveDesignFile.Models(CStr(ModelToBeCopied))
            Set model = ActiveDesignFile.Models.Copy(source, CStr(i))
            DoEvents
        Next i
        
        DoEvents
    End Sub

    1. But I obtained "Temp Views" and I'd prefer "Views". How could I do?

    2. I tried to attach in "Default" model a model already attached (as if it were the "Template" of your suggestion) and then move it ( the intention was to do some tests on the levels to verify that a single template model could be used and then copy it in different positions). So I attached again Model "31" in the "default" model and I tried to move it....but nothing happens: the frame (Hilite mode: Boundaries) of the reference selection does not appear, nothing appears when the reference is moved, etc... Why? :-O

    Thanks.

    Best regards,

    Paolo

  • Macro to add models

    It looks like your original question is answered.  Your new questions should be in new posts.

    I obtained "Temp Views" and I'd prefer "Views"

    Please explain what you mean.  Your code copies models, not views.

    I attached again Model "31" in the "default" model and I tried to move it....but nothing happens

    Show us your code!

     
    Regards, Jon Summers
    LA Solutions