sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Dynamic Component Copies and Transformation

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 447 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      JonD
      last edited by

      I have a script I am writing that I need the maximimum X distance from the model origin. The model contains dynamic components that are 'patterned' using the DC attribute 'Copies' to pattern along the x axis. There are multiple sub components in the model that each contain multiple copies using the DC Copies attribute. I am finding the max X by using the max point of the bounding box for the component and grabbing its X value. I am applying the tranformation of the parent (group or component instance) to the point to the max point. It seems that the transformation is not being applied correctly to the dc copies. The original DC of the copy is reporting correctly. Is the transformation of the copies (i.e. COPY >=1) based on the origin of the original DC? If so, any suggestions for managing the transformations correctly?

      Thanks,
      Jon

      1 Reply Last reply Reply Quote 0
      • J Offline
        JonD
        last edited by

        Ok, maybe this is totally unclear, so here is part of the code. I am using the method that Jim posted for 'cruising' throught the multiple levels (components, groups, and subcomponents) of the model:

        
        list = Array.new
        Sketchup.active_model.entities.each do |i|
        	list << {;item => i, ;trans => nil }
        end
        while list != []
        	list.each do |i|
        		item = i[;item]
        		type = item.typename
        		parenttrans = i[;trans]
        		case type
        			when "Group"
        				trans = item.transformation
        				trans = item.transformation*parenttrans if parenttrans
        				item.entities.each do |entity|
        					group_list << {;item => entity, ;trans => trans }
        				end
        				#get the attributes and put them in the report string
        				group_list.delete(item)
        			when "ComponentInstance"
        				name = get_attribute_value(item, 'name')
        				trans = item.transformation
        				trans = item.transformation*parenttrans if parenttrans
        				bbox = item.bounds
        				point = bbox.max.transform(parenttrans)
        				x = point.x
        				puts("x maximim; " + x.to_s)
        
        				item.definition.entities.each do |entity|
        					component_list << {;item => entity, ;trans => trans}
        				end			
        				#get rid of the item we have already examined in the list
        				component_list.delete(item)
        			end
        		end
        	list = group_list + component_list
        	group_list.clear
        	component_list.clear
        	end
        end
        

        I changed the method a bit to accumulate the transformation of the parents. It seems to work OK except for components in the model that are duplicated using the 'copies' dynamic component attribute...if anyone can shed light on this or has another method of getting the absolute location of a component, no matter how deeply nested, please post.

        Thanks,
        Jon

        1 Reply Last reply Reply Quote 0
        • M Offline
          markozeta
          last edited by

          Jon,

          I don't know much about Ruby, or components.

          I do know that the "generate report" function of pro version is a ruby script by google, and that it (for the most part) can read this problem. That being said, since this is the weekend and I only have my free version here, take my dynamic flange model (posted in the dynamic components section of these forums), which has multiple, multiple embeded copies as a test model. Run the "generate report" function on that model - I believe it will tell you what the X,Y,Z of each component is - and it will give you the same information as you've been getting. Not much help.

          So, that's what the attribute dictionary is getting. By searching, however, you can pull out information about the copies function (i.e. copy number). You can also find the formula for X,Y,Z by finding _X_Position_Formula (or something similar). Using the direct formula, you could in theory look for the word "copy" in the Position formula, and find out what X SHOULD BE by doing the math yourself.

          Not pretty, but that's the only thing I can think of until I play around with my pro version at work.

          BSME - Cal Poly Pomona
          Sketchup Pipe Maniac

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement