Grasshopper

algorithmic modeling for Rhino

Hi again. I´m trying to write a component to Insert CAD drawings at a given 3DPoint, based on a script to Import drawings that Rajaa Issa posted some time ago, but I find it quite difficult for I´m still learning VB.net. So I have 2 questions:
1- how can I refer the point for insertion in the app.RunScript (insert) command?
2- Is it possible to input several drawings (several paths) and match them to same number of points respectively? How? Will It respect the output ids_tree?

I started learning code the hard way: coding. My apologies for my lack of knowledge.

Thanks in advance



'Declare new list of points
    Dim new_points As List(Of On3dPoint)
    new_points = points

    'Select file objects and extract their uuids

    If( Not Open ) Then
      ids_tree = m_ids_tree
      Return
    End If

    If Open Then


      app.RunScript("-_insert _SaveRelativeFilePath=Yes " & sFileName & " _Objects " & point?/points? & " _Enter _Enter")


      app.RunScript("-_SelNone ")

    End If

    'Empty lists
    'm_ids_list.Clear()
    m_ids_tree.Clear()


    ' Dim context As IRhinoCommandContext

    ' Get a reference to the layer table
    Dim layer_table As MRhinoLayerTable = doc.m_layer_table
    ' Get the current layer
    Dim current_layer As IRhinoLayer = layer_table.CurrentLayer()

    For j As Integer = 0 To layernames.Count() - 1

      'Define a new guid list
      'Dim ids As New List(Of Guid)
      Dim path As New GH_Path(j)


      ' Prompt for a layer name
      Dim gs As String = layernames(j)
      Print(layernames(j))

      ' Validate the string
      Dim layer_name As String = gs.Trim()

      ' Find the layer
      Dim layer_index As Integer = layer_table.FindLayer(layer_name)

      ' Get the layer
      Dim layer As IRhinoLayer = layer_table(layer_index)

      ' Get all of the objects on the layer
      Dim obj_list As MRhinoObject() = Nothing
      Dim obj_count As Integer = doc.LookupObject(layer, obj_list)


      'Iterate through all objects and isolate their uuids
      For i As Integer = 0 To obj_count - 1
        Dim id As Guid
        id = obj_list(i).ModelObjectId
        Print(id.ToString)
        'ids.Add(id)
        m_ids_tree.Add(id, path)
      Next





      'Add to private list
      'm_ids_list.Add(ids)



    Next

    'Output names
    'ids_list = m_ids_list
    ids_tree = m_ids_tree
    A = sFileName


Views: 1406

Attachments:

Replies to This Discussion

I made some changes and it compiles now without errors. It also inserts the geometry in G:\Drawing1.dwg, but I don't know if the bit with the layers is working as intended.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Attachments:
Oh la la! Interesting thing this "pt_cmd_string" . This script works perfectly for one single file input, we almost have it but there is a final step unsolved: when we have a list of Filenames and need them to match with same number of points...
Should we use For Each...Filename...?

I really appreciate your help, your time spent in my question and I hope this solutions help as many people as possible!!!! I do believe.

Thank you so much. Sorry for my ignorance.


Attachments:
You can either convert the sFileName and point inputs to list and iterate over them, or you can let Grasshopper handle the looping. Just accept a single filename and a single point, and if someone supplies 10 of each, then you'll script will get called 10 times in a row.

--
David Rutten
david@mcneel.com
Poprad, Slovakia

Hi There,

Really in need of component like this. Unfortunately it doesn't seem to work with Rhino5 I think the insert commands has changed a bit. I tried to play with the code but I couldnt get it to work. Any ideas for a fix?

Hi Joonas,

Try this one.

It requires ghPython plugin to be installed first.

If you do not supply "layer" (like in screenshot above), geometry from imported file will be imported along with its respective layers. Otherwise (if you supply the "layer") all that new imported geometry will be sent to the "layer".

Attachments:

This works fine but it bakes the dwg:s immediately and I want to move them into a pointgrid made in GH. 

Hi djordje.

Did you ever do something like this, but only import selected layers on a dwg? Say that you have a lot of information in a dwg file, but you only want to import a certain layer?

I guess maybe the workaround, is to import everything and the delete the "unwanted" layers automatically.

Rasmus

Yes, I think that would be the only option with usage of Rhino's "Import" command. There may be some other way of importing only specific layers, but some custom plugin for opening and manipulating .dwg files would need to be written.

Thanks- This was very helpful!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service