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

    Posts

    Recent Best Controversial
    • [Sketchup C API] Set mm as units of newly created model?

      I see that there is a way to get units SUModelGetUnits from the model. But no method to Set the units for the model/file.

      So, is it possible to set the units?
      If yes, what is the method or is there any other indirect way - such that the new file gets saved with "Millimeters" units?

      Note:This question has been posted earlier as part of this thread http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=57909.
      Since this is a different question from the original thread I have added it separately.

      posted in Developers' Forum
      R
      rahulnejanawar
    • RE: [Sketchup C API]Howto merge models oftwo .skp files into one

      Thank you Thomas. We got the whole thing working except for one small thing. We need your input for the same.

      Problem: The files m1 and m2 which we want to merge to m3 - have the "Millimeters" units. But the merged file m3 gets saved with "Inches" units. I see that there is a way to get SUModelGetUnits from the model. But no method to Set the units for the model. Is there any method (any other indirect way) - such that the new file gets saved with "Millimeters" units?

      By the way the approach for merging is below and it works for us.

      1. Get the models of each of the file, say m1,m2.
      2. Get entities of m1 and m2, say e1,e2.
      3. Get Instances from e1 and e2, say i1, i2 ( assume we have 1 instance in each model)
      4. Get Definition of i1 and i2, say d1 and d2
      5. Create new instances of d1 and d2, ni1 and ni2
      6. Create a new empty model , say new_model
      7. Get the entities of new_model, say new_entities
      8. Now add ni1 and ni2 to new_entities
      9. Save the new_model to file
      10. Release the memory

      We are yet to work on the transformations for merging

      posted in Developers' Forum
      R
      rahulnejanawar
    • [Sketchup C API]Howto merge models oftwo .skp files into one

      Assumption: My models contain only ComponentInstances.

      My Approach:

      1. Get the models of each of the file, say m1,m2 (using SUModelCreateFromFile).
      2. Get entities of m1 and m2, say e1,e2 (using SUModelGetEntities).
      3. Get ComponentInstances from e2 (using SUEntitiesGetInstances).
      4. In a loop add each of the ComponentInstance of e2 into e1 (using SUEntitiesAddInstance).
      5. Write the model m1(with entities e1) to a new file.
        //The new file contains the ComponentInstances of m1,m2.

      Where I am stuck?
      In the below code.

      On a high level the below program does three things

      1. It gets the Model from file.
      2. From Model it gets Entities.
      3. From Entitites it gets ComponentInstances. Here it fails.
      #include <slapi/slapi.h>
      #include <slapi/geometry.h>
      #include <slapi/initialize.h>
      #include <slapi/model/model.h>
      #include <slapi/model/entities.h>
      #include <slapi/model/face.h>
      #include <slapi/model/edge.h>
      #include <slapi/model/vertex.h>
      #include <vector>
      #include <iostream>
      #include <stdio.h>
      int main() {
        // Always initialize the API before using it
        SUInitialize();
        // Load the model from a file
        SUModelRef model_to_write1 = SU_INVALID;
          SUResult m1 = SUModelCreateFromFile(&model_to_write1, "model11.skp");
        if(m1 == SU_ERROR_NONE)
      	std;;cout<<"SUModelCreateFromFile SUCCESS!!!!!";
        else if(m1 == SU_ERROR_NULL_POINTER_INPUT)
          std;;cout<<"Error_Entities -- Inside 1 file are";
        else if(m1 == SU_ERROR_NULL_POINTER_OUTPUT)
          std;;cout<<"NULLPOINTER_Entities -- Inside 1 file are";
        else 
      	  printf("None of the above");
      
       SUEntitiesRef entities1 = SU_INVALID;
       size_t* size1 = NULL;
       SUComponentInstanceRef comp1[10];
       SUResult result = SUModelGetEntities(model_to_write1, &entities1);
       if(result == SU_ERROR_NONE)
      	std;;cout<<"\n SUModelGetEntities SUCCESS !!!!!";
       if(result == SU_ERROR_INVALID_INPUT)
          std;;cout<<"Error_Entities Inside 1 file are";
       if(result == SU_ERROR_NULL_POINTER_OUTPUT)
          std;;cout<<"NULLPOINTER_Entities Inside 1 file are";
      
        result = SUEntitiesGetInstances(entities1,2,comp1,size1);
        if(result == SU_ERROR_NONE)
      	std;;cout<<"\n SUEntitiesGetInstances SUCCESS";
        else if(result == SU_ERROR_INVALID_INPUT)
          std;;cout<<"\n Error_Copy";
        else if(result == SU_ERROR_NULL_POINTER_OUTPUT)
          std;;cout<<"\n NULLPOINTER";
        // Save the in-memory model to a file
        SUModelSaveToFile(model_to_write1, "very_new_model.skp");
        SUTerminate();
        getchar();
        return 0;
      }
      
      

      Output:
      SUModelCreateFromFile SUCCESS!!!!!
      SUModelGetEntities SUCCESS !!!!!
      NULLPOINTER

      Questions:

      1. In the above output I am getting NULLPOINTER(3rd line) which is the result of call SUEntitiesGetInstances(entities1,2,comp1,size1) in the above program. Why I am not able to get the ComponentInstances?
      2. Can you please review the approach which is mentioned at the beginning and let me know if is it right?

      model11.skp

      posted in Developers' Forum
      R
      rahulnejanawar
    • RE: How to read .skp files in ruby?

      Thank you

      posted in Developers' Forum
      R
      rahulnejanawar
    • How to read .skp files in ruby?

      Hi,

      I have written some plugins and I have some .skp files containing some models.

      I want to be able to read these files programmatically and run my plugins on those models. Is it possible?.

      I read about Sketchup C API. This is C. My plugins in ruby. So I was not sure how to use them together. Is the ability to read .skp files and get models available in ruby? Any pointers to examples?

      posted in Developers' Forum
      R
      rahulnejanawar
    • RE: How to check if two ComponentInstances are in contact?

      Thank you sir.

      posted in Developers' Forum
      R
      rahulnejanawar
    • How to fetch all material in SKP via Ruby?

      Hi,

      Is it possible to fetch all material items which are appear in the Sketchup materials window by ruby?
      Is there any function which do the above work ie which can access the all items(material type) in the Materials?

      I found that the below function which works for Model-

      
      model = Sketchup.active_model
      matrials = model.materials
      materials[0].name ==> gives name of the material
      

      Like this above any other function by which we can retrieve the all Material items which are present in Sketchup Materials(class index).

      posted in Developers' Forum
      R
      rahulnejanawar
    • How to check if two ComponentInstances are in contact?

      Hi,
      Is it possible to know if a given ComponentInstance is in contact (touching) with another Component Instance? If yes, which Face is in contact?
      (Given that my ComponentInstance is an rectangle box as shown in the attached image)

      Consider the attached image. B is in contact with A. The bottom Face of B is the Face that is in contact. If these two ComponentInstances (A & B) are ‘selected’ can I programmatically get the bottom Face object of B? And top Face object of A?
      d1.jpg
      I tried the glued_to method on the ComponentInstance but that seems to mean(do) something different from what I want to achieve.

      Your help is appreciated.

      posted in Developers' Forum
      R
      rahulnejanawar
    • 1 / 1