sketchucation logo sketchucation
    • Login
    1. Home
    2. YoungOSG
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    Y
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 12
    • Posts 31
    • Groups 1

    Posts

    Recent Best Controversial
    • Group moves far away when i want to scale

      t = Geom::Transformation.scaling 2
      group.transform! t
      i use above code to scale s group,however the group always move far away!
      I can not figure it out.
      anyone helps!! thanks!


      QQ截图20150530213141.png


      QQ截图20150530213155.png

      posted in Developers' Forum
      Y
      YoungOSG
    • RE: [Plugin] Import ALL from Folder

      @tig said:

      @Young

      You code is overly complicated.
      It also has some odd working practices... 😕

      I am sure I have answered this same query elsewhere...
      See the @yuyuwhy posts...
      Is it you, but with a different user-name ??
      http://sketchucation.com/forums/viewtopic.php?p=554042#p554042

      This thread explains how to setup an empty model SKP - the order of purging IS important - yours is wrong !
      Do that BEFORE importing anything.

      It also suggests a sensible approach to the subsequent import, purge and export of each DAE in turn.
      If you enclose those actions within a ' model.start_operation(...)' block, BUT afterward each you ' model.abort_operation' it [NOT the usual ' model.commit_operation' it] then the imported data is simply forgotten, but the export is safe because the DAE file is now outside of the SKP's control... So there is no need to purge between each import/export at all.

      Recast your code thus...
      Make the host SKP empty.
      Process the list of DAE files in turn.
      Use a model.start_operation(...) block around each iterate step.
      Remember to use the model.abort_operation to undo the import etc, but leave the export intact.
      You should end up with an empty SKP and all of the DAE files processed.

      Incidentally, your code only works in v2015 as the UI folder selector is new in that version's API.

      Thanks!! I tried and it works!
      And I want to import *.dae file with 2000 jpg.However Sketchup stop at 10%. It do not warn me anything.
      could you help me ?

      posted in Plugins
      Y
      YoungOSG
    • Detecting two components and/or groups are intersected?

      How to detecting two components and/or groups are intersected or not?

      posted in Newbie Forum sketchup
      Y
      YoungOSG
    • RE: [Plugin] Import ALL from Folder

      @driven said:

      I only use mac, but...

      you could, save each file to 'Trash', close it, then open a new for the next import?

      SU should then be starting fresh each time and you don't need to erase any entities?

      just a thought, I use the idea in a script...
      this is the an extract for Trash on a mac...

      def revert
      >   trash_copy = (File.expand_path("~/.Trash/" + "." + @orig.title + ".skp")).dup.freeze
      >   @orig.save(trash_copy)
      >   Sketchup.send_action("closeDocument;")
      >   Sketchup.send_action("newDocument;")
      > end
      

      john

      Thanks!
      I tried it.It works fine on my PC,however it crashed on others.

      posted in Plugins
      Y
      YoungOSG
    • RE: [Plugin] Import ALL from Folder

      @tig said:

      You said 'ade', I guess you really meant '.DAE' ?
      They should import OK.
      Any error messages in the Ruby Console when try it ??

      Yes! I mean *.dae files.
      I use your script.and add purge_unsed,export.
      However i need to handle thousands of files.Sketchup always crashes after export few files.
      I really don't know how to fix it.
      any helps?


      purge_multi_dae2 (2).rb

      posted in Plugins
      Y
      YoungOSG
    • Sketchup crashes when import,purge_unused,export dae files

      Sketchup crashes when import,purge_unused,export hundreds of *.dae files.
      I use api to do this.It works fine while handling few *.dae files.
      anyone konws why?

      Here is my code

      require 'sketchup.rb'
      require 'fileutils'

      UI.menu("Plugins").add_item("purge_multi_daeE") {

      @import_folder = selectImportDaefolder()
      break if @import_folder==nil
      @export_folder = selectExportDaefolder()
      break if @export_folder==nil
      
      
      @daeFiles = getDaeFiles(@import_folder,".dae")
      
      
      purgeDaeFile(@daeFiles,@import_folder,@export_folder)
      
      
      
      Sketchup.send_action("selectSelectionTool:")
      

      }

      def purgeDaeFile(daeFiles, import_folder,export_folder)
      model = Sketchup.active_model

      subName = getDirName(import_folder)
      Dir.chdir(export_folder)
      FileUtils.rm_r subName if Dir.exist?(subName)	
      
      
      i = 0
      Dir.mkdir(subName)
      daeFiles.each{|singleDaeFile|
      	Sketchup::set_status_text("purge " + File.basename(singleDaeFile))
      
          status = Sketchup.active_model.definitions.purge_unused
       
      	f.puts(singleDaeFile)
      
      	importDaeFile(singleDaeFile)
      
      
      	purgeModel()
      
      
      	resultFileName = File.join(export_folder,subName,File.basename(singleDaeFile))
      	Sketchup.active_model.export(resultFileName, false)
      
      
      	deleteLastModel()
      	
      }
      

      end#def

      purge dae model

      def purgeModel()
      # 1. purge styles
      styles = Sketchup.active_model.styles
      status = styles.purge_unused

      # 2. purge materials 
      materials = Sketchup.active_model.materials
      materials.purge_unused
      
      # 3. purge definitions
       definitions = Sketchup.active_model.definitions
       status = definitions.purge_unused
      
      # 4. purge layers
      layers = Sketchup.active_model.layers
      status = layers.purge_unused
      

      end#def

      导入dae file

      def importDaeFile(singleDaeFile)
      model = Sketchup.active_model
      model.import(singleDaeFile,false)
      entities = model.entities
      definitions = model.definitions
      definitions.each {|definition|
      transformation = Geom::Transformation.new([0,0,0])
      componentinstance = entities.add_instance(definition, transformation)
      }

      Sketchup.send_action("selectSelectionTool:")
      

      end#def

      def deleteLastModel()
      model = Sketchup.active_model
      entities = model.active_entities
      entities.erase_entities entities.to_a

      end#def

      posted in Newbie Forum sketchup
      Y
      YoungOSG
    • RE: [Plugin] Import ALL from Folder

      @tig said:

      @mattao987 said:

      ...I'd like to add an optionnal STAGE in your script.
      Once a file is imported, i'd like to create a new layer named by reference to the file name with a suffix.
      Let's say Wonka_Niv1
      Then, Group all the freshly imported items on this new layer.
      Then proceed to the next file...

      What file type are you importing?
      SKP and Others need to be treated differently...
      Obviously none of this 'Layering' stuff will ever work with imported 'Images' !!

      For non-SKP files:
      Provided there is at least one object already in the receiving-SKP, then all imported formats [other than a SKP] will already import as a component named after the file - e.g. "Wonka_Niv1.dwg".
      So after line#84:
      model.import(file,false)
      add these lines:
      unless File.extname(list[0]).downcase==".skp" ins=model.definitions[File.basename(file)].instances[0] ins.layer=model.layers.add(File.basename(file, ".*")) end#if
      Note: this uses the imported files 'basename' [e.g. "Wonka_Niv1"], to use the full name with say its '.dwg. suffix use ...add(File.basename(file)) instead

      For SKP imports you will need to edit another part of the code:
      after line#107:
      ins=model.active_entities.add_instance(defn,tr)
      add this:
      ins.layer=model.layers.add(name)
      This uses the imported SKP's name, without any '.skp' suffix [e.g. "Wonka_Niv1"] - but if you want to add one, then change ...add(name) to ...add(File.basename(file))

      This should do what you want... 😄

      after i use this plugins to add ade files,i can not see them!
      i can not understand why.
      any helps?

      posted in Plugins
      Y
      YoungOSG
    • RE: I have a question, about Model.import of sketchup API

      @thomthom said:

      Do you get any errors?
      What format are you trying to import? .skp?

      I import a dae file to sketchup by api. but i need to click to position. is there a way to position it automatically?

      posted in Developers' Forum
      Y
      YoungOSG
    • How to set a position for a import dae file

      i used api to import dae file ,however it needs a left-click to position.
      but i have many dae files , is there a way to give it a position automatically?
      THANKS!

      posted in Newbie Forum sketchup
      Y
      YoungOSG
    • RE: Lines won't break a face

      @tig said:

      If the face[s] and the rectangle that won't 'cut' are indeed coplanar select them both and "Intersect" them. they will now break... [it works I tried it... 😉 ]

      if i want use sketchup api to do this,how should i do?
      thanks!

      posted in SketchUp Discussions
      Y
      YoungOSG
    • Edge cann't split a face to two faces

      i use extrudeEdgesByVectorToObject to extend.but i expolde all groups and edge is within the face ,because i use point_in_polygon_2D to test it.however it cann't split a face to two faces.
      and i draw this edge by hand ,it will split.
      anyone konws why?


      41@C0W}O4EXXTLDY8Q44_V2.jpg

      posted in Newbie Forum sketchup
      Y
      YoungOSG
    • RE: How to get face which is belong to two group

      @tig said:

      Get

      tr1=group1.transformation
      > tr2=group2.transformation
      

      You need those th apply to things later...

      The two 'coincident' faces in question will have some similar properties [when adjusted for their container's transformation].
      You need to iterate the faces in group1 to get a suitable in group2

      faces1=group1.entities.grep(Sketchup;;Face)
      > faces2=group2.entities.grep(Sketchup;;Face)
      > face2=nil
      > face1=nil
      > faces1.each{|face|
      >   min=face.bounds.min.transform(tr1)
      >   max=face.bounds.max.transform(tr1)
      >   norm=face.normal.max.transform(tr1)
      >   faces2.each{|f|
      >     if f.bounds.min.transform(tr2)==min && f.bounds.max.transform(tr2)==max && f.normal.transform(tr2)==norm.reverse
      >       face2=f
      >       face1=face
      >       break
      >     end
      >   }
      >   break if face2
      > }
      > ### face2 is the matching face in group2, if not nil !  Delete it !
      > ### face1 is the matching face in group1
      

      This is NOT foolproof.

      BUT you can add extra tests...
      For example... collect the loops of face2, collect their vertices as points and transform them, then compare with the loop-vertices-points-transformed of face1, if there are any mismatches then the two faces are NOT completely coincident - e.g. one of the otherwise coincident could have a side-notch or a hole in it, but still have the same normal and bounds !
      You need to make these decisions... Simple boxes ?

      one more question.if there are many groups,how can i get the groupA which is adjacent with groupB.
      i intend to judge by distance.is there any easy way to do this?

      posted in Developers' Forum
      Y
      YoungOSG
    • RE: How to get face which is belong to two group

      @tig said:

      Get

      tr1=group1.transformation
      > tr2=group2.transformation
      

      You need those th apply to things later...

      The two 'coincident' faces in question will have some similar properties [when adjusted for their container's transformation].
      You need to iterate the faces in group1 to get a suitable in group2

      faces1=group1.entities.grep(Sketchup;;Face)
      > faces2=group2.entities.grep(Sketchup;;Face)
      > face2=nil
      > face1=nil
      > faces1.each{|face|
      >   min=face.bounds.min.transform(tr1)
      >   max=face.bounds.max.transform(tr1)
      >   norm=face.normal.max.transform(tr1)
      >   faces2.each{|f|
      >     if f.bounds.min.transform(tr2)==min && f.bounds.max.transform(tr2)==max && f.normal.transform(tr2)==norm.reverse
      >       face2=f
      >       face1=face
      >       break
      >     end
      >   }
      >   break if face2
      > }
      > ### face2 is the matching face in group2, if not nil !  Delete it !
      > ### face1 is the matching face in group1
      

      This is NOT foolproof.

      BUT you can add extra tests...
      For example... collect the loops of face2, collect their vertices as points and transform them, then compare with the loop-vertices-points-transformed of face1, if there are any mismatches then the two faces are NOT completely coincident - e.g. one of the otherwise coincident could have a side-notch or a hole in it, but still have the same normal and bounds !
      You need to make these decisions... Simple boxes ?

      thanks! you always be the super star 😍

      posted in Developers' Forum
      Y
      YoungOSG
    • RE: How to get face which is belong to two group

      @cotty said:

      If there is one face (in one of the groups) or if there are two faces (one in each group) depends on the way you created the groups. You can always enter one group, copy the face to the clipboard and paste (in place) it outside those groups to get a single face independent of the groups.

      i think i don't explain it clearly. there are two faces (one in each group),as you say. and when i explode two groups,i can get 11 faces which 1 face is delete.
      i wanna use api to get this face in groupA which in groupB also has this face .i mean they are occupy same region.but they are different.
      can i do it by judge face's vertices position or some other ways?

      posted in Developers' Forum
      Y
      YoungOSG
    • How to get face which is belong to two group

      there are two groups .i wanna to get the face ,which is belong to two groups.just like two walls,there is a face which can be think to belong any wall.
      as the picture.
      how can i can get the face?
      thanks


      ![[7DSPY@EF_WPWXB8)3XSO8.jpg

      posted in Developers' Forum
      Y
      YoungOSG
    • How should i judge points can construct face or not

      i'm writing a plugin to read points from xml. however sometimes points cann't construct face ,the plugin
      will stop working.

      how can i judge points can construct face or not? or can i just skip ,when points isn't qualify?

      any helps? thanks!!

      posted in Developers' Forum
      Y
      YoungOSG
    • How shoulid i to extend with more than 4 edges

      just like the pictures.

      the face has 6 edges.and i want to extend it to fill up the gap with the top faces.
      the problem is there are 3 faces ,and i need to extend the face to them ,make sure there are no gaps any mnore.

      is there any plugins to do this ?

      thanks for help!


      ![O78MNJY}RAIZ5025WYAH.jpg

      posted in Newbie Forum sketchup
      Y
      YoungOSG
    • RE: Is there a way to judge a edge is through face or not?

      @tig said:

      Simple way. 🤓
      Get the ' vector' from the center-point [ point1] to the other external-point [ point2].
      vector = point1.vector_to(point2)
      Now do a ' raytest': using...
      raytest = Sketchup.active_model.raytest([point1, vector])
      The ' raytest' will be nil if nothing is hit, BUT since you say there is always geometry surrounding point1 that should never occur.
      So it succeeds and returns an array with two elements: raytest[0] is the point of intersection and the second element, raytest[1] is an array: that array contains the 'hits' in nested order - with any geometry listed last.
      So the last item raytest[1][-1] is a reference to the 'face' that is intersected.
      Note that it might be an 'edge' if the points and geometry are such that the 'ray' passes through the intersection of two or more faces.
      Other elements in that array [if any] represent the 'container' references - like group or component if applicable - these are in nested order...

      thanks.it works.

      posted in Newbie Forum
      Y
      YoungOSG
    • RE: Is there a way to judge a edge is through face or not?

      @dave r said:

      As I already asked, why do you need a plugin to see if the edge passes through the face?

      Maybe you could explain what you really need to do.

      i have a cube . and i konw the center of the cube ,and a point outside the cube. connect this two point , i want to konw which face will be through?

      posted in Newbie Forum
      Y
      YoungOSG
    • RE: Is there a way to judge a edge is through face or not?

      @sdmitch said:

      @youngosg said:

      I mean have any plugins to do it?

      Probably not but would be easy enough to create one. How would want it to work?

      i have a cube . and i konw the center of the cube ,and a point outside the cube. connect this two point , i want to konw which face will be through?

      posted in Newbie Forum
      Y
      YoungOSG
    • 1 / 1