Not working arrays for Facet. Why?

What wrong in this code? I'm try to get vertexes in current facet.

m_normIdx [4], m_uvwIdx [4] also don't working :(


var oNode = Scene.getPrimarySelection();
if( oNode ){
var oObject = oNode.getObject();
var oShape = oObject.getCurrentShape();
var oGeometry = oShape.getGeometry();
var oFacet = oGeometry.getFacet(0);
for( k = 0; k < 4; k++ ) {
var currentVertex = oGeometry.getVertex(oFacet.m_vertIdx[k]);
~~~~~~~~~~~~~~~
}
}

TypeError: Result of expression 'oFacet.m_vertIdx' [undefined] is not an object.

Comments

  • Richard HaseltineRichard Haseltine Posts: 96,858
    edited November 2012

    Edit - while I stand by my advice below, you should also check the type of oGeometry. I don't see getFacet() in the DS 3 scripting docs, and I don't see m_vertIdx as a member of any of the facet types which may be your biggest problem - it isn't defined by you either.

    ---------------------------------------------------

    Try adding some error checking - I suspect you're being too trusting and not ending up with a facet.

    var oNode = Scene.getPrimarySelection();
    if( oNode ){
     var oObject = oNode.getObject();
     if (oObject) {
      var oShape = oObject.getCurrentShape();
      if (oShape) {
       var oGeometry = oShape.getGeometry();
       if (oGeometry) {
        var oFacet = oGeometry.getFacet(0);
        if (oFacet) {
         for( k = 0; k < 4; k++ ) {
          var currentVertex = oGeometry.getVertex(oFacet.m_vertIdx[k]);
                                                                          ~~~~~~~~~~~~~~~
         }
        }
        else {
         print ( "No facet" );
        }
       }
       else {
        print ( "No geometry" );
       }
      }
      else {
       print ( "No shape" );
      }
     }
     else {
      print( "No object" );
     }
    }
    else {
     print( "No node" );
    }
    Post edited by Richard Haseltine on
  • edited December 1969

    Same result with checking :(

    Script Error: Line 12
    TypeError: Result of expression 'oFacet.m_vertIdx' [undefined] is not an object.


    From last SDK documentation:

    http://www.daz3d.com/shop/daz-studio-4-5-sdk

    file:
    C:\Program Files\DAZ 3D\DAZStudio4 SDK\docs\class_dz_facet.html

    ---
    DzFacet Class Reference
    [Object and Geometry Classes]

    Represents a polygonal face. More...

    Public Attributes
    ...
    int m_normIdx [4]
    int m_uvwIdx [4]
    int m_vertIdx [4]
    ...
    DzFacet::m_vertIdx[4]
    Array of vertex indices that make up the face. m_vertIdx[3] will be -1 if this is a triangle.

  • Richard HaseltineRichard Haseltine Posts: 96,858
    edited December 1969

    That's the SDK, not the Scripting kit - they are not the same.

  • edited December 1969

    My fault :)

    Whether there is a fresh version of Scripting kit? In DazStudio 4.5 it seems any more polygons, only triangles and quads are supported?

  • Richard HaseltineRichard Haseltine Posts: 96,858
    edited December 1969

    There are a couple of samples related to mesh generation, which isn't of course what you are doing but it may be helpful:
    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/geometry/generate_plane/start
    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/geometry/generate_sphere/start

    You can also use Rob's trick to see what members an object has:

    var object = new DzWhatever; // or get an example of the object type from the scene
    for ( var n in object) {
         print( n );
    }
  • almancarlaalmancarla Posts: 6
    edited December 1969

    Have you solved the problem yet?
    Recently,my problem was how to add a single arrow to only one facet. Recently I installed a new version of R:

    platform i386-pc-mingw32
    version.string R version 2.14.2 (2012-02-29) ggplot2_0.9.0

    Here is the code example
    xdf <- data.frame(x=rep(1:10,each=4)<br /> ,y=rep(1:10,each=4)*rep(1:4,10) +rnorm(40,0,1)
    ,g=rep(c("R","S"),20)
    ,z=rep(c("A","A","B","B"),10)
    )
    head(xdf)
    # plot
    xp <- ggplot(xdf,aes(x=x,y=y, group=g)) +<br /> geom_line() +
    facet_grid(. ~ z)
    xp
    # location of the arrow: x=4, y=y+1 on the top of the first facet (A)
    (f1x4 <- subset(xdf,x==4 & g=="R" & z=="A")$y)<br /> arrdf <- data.frame(x = 4, y = f1x4, z = "A", g = "R") # create new data.frame for annotations<br /> # add arrow and label
    xp + geom_segment(data=arrdf,aes(x=x,xend=x,y=y+3,yend=y,z=z,g=g) # <-- see the z='A'<br /> , arrow=arrow(length=unit(0.4,"cm")
    )
    ) +
    geom_text(data=arrdf,aes(x=x,y=y+4, label="a",z=z, g=g))

Sign In or Register to comment.