Revnixcad Posted January 19, 2022 Posted January 19, 2022 (edited) With the following command you can select a line in attached drawing and retrieve data(using attached DWG): (dictsearch (handent (cdr (assoc 5 (entget (cdr (assoc 360 (entget (car (entsel))))))))) "ESRI_Attributes" ) With this we receive the following data(on some line): ((-1 . <Entity name: 1e75859a920>) (0 . "DICTIONARY") (5 . "83C2") (102 . "{ACAD_REACTORS") (330 . <Entity name: 1e75859a910>) (102 . "}") (330 . <Entity name: 1e75859a910>) (100 . "AcDbDictionary") (280 . 1) (281 . 1) (3 . "AFSTROMING") (360 . <Entity name: 1e75859aa50>) (3 . "BEMALINGSGEBIED") (360 . <Entity name: 1e75859ab00>) (3 . "BOB_B") (360 . <Entity name: 1e75859aa70>) (3 . "BOB_E") (360 . <Entity name: 1e75859aa80>) (3 . "DIAMETER") (360 . <Entity name: 1e75859ab30>) (3 . "FE") (360 . <Entity name: 1e75859ab60>) (3 . "FUNDERINGSTYPE") (360 . <Entity name: 1e75859a9b0>) (3 . "GLOBALID_BEGINKNOOP") (360 . <Entity name: 1e75859ab80>) (3 . "GLOBALID_EINDKNOOP") (360 . <Entity name: 1e75859ab90>) (3 . "GN_CREATED_DATE") (360 . <Entity name: 1e75859a950>) (3 . "GN_CREATED_USER") (360 . <Entity name: 1e75859a940>) (3 . "GN_LAST_EDITED_DATE") (360 . <Entity name: 1e75859a970>) (3 . "GN_LAST_EDITED_USER") (360 . <Entity name: 1e75859a960>) (3 . "INSPECTIE_DATUM") (360 . <Entity name: 1e75859aab0>) (3 . "JAAR_GELEGD") (360 . <Entity name: 1e75859aa90>) (3 . "JAAR_INWINNING_BOB_B") (360 . <Entity name: 1e75859aba0>) (3 . "JAAR_INWINNING_BOB_E") (360 . <Entity name: 1e75859abb0>) (3 . "JAAR_ONDERZOEK_GEPLAND") (360 . <Entity name: 1e75859aac0>) (3 . "KAARTBLAD_1000") (360 . <Entity name: 1e75859a9a0>) (3 . "LENGTE") (360 . <Entity name: 1e75859aaa0>) (3 . "LIGGING_TERREIN") (360 . <Entity name: 1e75859a9f0>) (3 . "MATERIAAL") (360 . <Entity name: 1e75859ab20>) (3 . "MATERIAAL_SPECIFICATIE") (360 . <Entity name: 1e75859aa00>) (3 . "OBJECTID") (360 . <Entity name: 1e75859a930>) (3 . "OBJECTNUMMER") (360 . <Entity name: 1e75859a990>) (3 . "OORSPRONG_AFMETING") (360 . <Entity name: 1e75859a9c0>) (3 . "OORSPRONG_BOB_B") (360 . <Entity name: 1e75859a9d0>) (3 . "OORSPRONG_BOB_E") (360 . <Entity name: 1e75859a9e0>) (3 . "PROCESSED_FLAG") (360 . <Entity name: 1e75859a980>) (3 . "REDEN_MAATREGEL") (360 . <Entity name: 1e75859aa10>) (3 . "REVISIE_TEKENING") (360 . <Entity name: 1e75859aaf0>) (3 . "Shape__Length") (360 . <Entity name: 1e75859abc0>) (3 . "SOORT") (360 . <Entity name: 1e75859ab40>) (3 . "STABILITEIT") (360 . <Entity name: 1e75859aa40>) (3 . "STATUS") (360 . <Entity name: 1e75859ab10>) (3 . "STELSEL_TYPE") (360 . <Entity name: 1e75859aad0>) (3 . "STROOMGEBIED") (360 . <Entity name: 1e75859aa20>) (3 . "TEKENING_DISTRICT") (360 . <Entity name: 1e75859aae0>) (3 . "TYPE") (360 . <Entity name: 1e75859ab50>) (3 . "VORM") (360 . <Entity name: 1e75859aa60>) (3 . "WATERDICHTHEID") (360 . <Entity name: 1e75859aa30>) (3 . "ZUIVERINGSKRING") (360 . <Entity name: 1e75859ab70>) ) if i drill down this dictionary we get a XRECORD with the value and containing ACAD_REACTOR. My question is as follows: Draw a new line with layername "N-OI-RI-TRANSPORTRIOOL_LEIDING_NG_600-G" retrieve the information from this layername with following lisp function: (defun c:add-new-line (/ $activeDoc $diameter $entGet $entSel $i $intermediate $layerName $layerTable $materiaalLabel $n $obj $objSelect $splitResult $stelsel ) (setvar 'Cmdecho 0) (setvar 'Regenmode 0) (vl-load-com) (setq $activeDoc (vla-get-activedocument (vlax-get-acad-object) ) ) (setq $layerTable (vla-get-layers $activeDoc)) (setq $objSelect (ssget)) (setq $i 0 $n (sslength $objSelect) ) (while (< $i $n) (setq $entSel (ssname $objSelect $i)) (setq $entGet (entget $entSel) $i (1+ $i) ) ; N-OI-RI-TRANSPORTRIOOL_LEIDING_NG_600-G (setq $layerName (cdr (assoc 8 $entGet))) (setq $intermediate (nth 3 (LM:stringToList $layerName "-"))) (setq $splitResult (LM:stringToList $intermediate "_")) (setq $stelsel (nth 0 $splitResult)) (setq $leidingLabelName (nth 1 $splitResult)) (setq $materiaalLabel (nth 2 $splitResult)) (setq $diameter (nth 3 $splitResult)) (if (= $diameter nil) (setq $diameter "0") ) ) (vla-put-activelayer $activeDoc (vla-item $layerTable 0)) (setvar 'Cmdecho 1) (setvar 'Regenmode 1) (princ (strcat $stelsel ", " $leidingLabelName ", " $materiaalLabel ", " $diameter)) (princ) ) This function prints "TRANSPORTRIOOL, LEIDING, NG, 600" from each value i want to create a xrecord(this i can do) and add(this i cant do) the information to the existing ESRI_attributes dictionary. I tried to get the hang of ACAD_REACTORS but can't figure it out how to realise this. Hope somebody here can give me good advice which direction to go. 1483869724_TESTAWREACTORDATA.dwg Edited January 19, 2022 by Revnixcad Quote
BIGAL Posted January 19, 2022 Posted January 19, 2022 Check out afralisp has some good tutorials about xdata and adding to an existing dictionary. Quote
tombu Posted January 20, 2022 Posted January 20, 2022 If Civil 3D is an option for you the videos here may help: https://civilimmersion.typepad.com/civil_immersion/2022/01/display-civil-3d-property-set-data-in-tooltips.html Quote
Revnixcad Posted January 24, 2022 Author Posted January 24, 2022 Together with my colleague @Semx11 we figured it out. Based on the code from the pdf mentioned above "Writing a Feature Class to the Named Object Dictionary" on page 3. But instead of writing it to feature class we write the information to an object entity. We added (vla-GetExtensionDictionary and it worked. See code below. (defun c:gisAddAttributesToEntity (/ $featureAttributes $objFeatures $objFeatureClass $objDict $objFeatureAttributes $fieldnameInt $fieldnameLong $fieldnameReal $fieldnameText $objResB $objList $objXrecd $objFieldInt $objFieldLong $objFieldReal $objFieldText ) (vl-load-com) ; ECHO COMMAND TO SCREEN (prompt "ADD ATTRIBUTES TO ENTITY") (princ) ; SET OBJECT NAME FOR THE ATTRIBUTE DICTIONARY (setq $featureAttributes "ESRI_Attributes") ; SELECT ENTITY (setq $entity (car (entsel))) ; GET OR ADD EXTENSION DICTIONARY (setq $vlaDict (vla-GetExtensionDictionary (vlax-ename->vla-object $entity))) (setq $extensionDict (vlax-vla-object->ename $vlaDict)) ; CHECK IF EXTENSION DICTIONARY EXISTS (if (/= $extensionDict nil) (progn ; FIND/ADD THE ATTRIBUTES DICTIONARY (if (= (dictsearch $extensionDict $featureAttributes) nil) ; CREATE A NEW DICTIONARY IF NOT FOUND (progn ; CREATE A DICTIONARY ENTRY LIST (setq $objList (list '(0 . "DICTIONARY") '(100 . "AcDbDictionary"))) ; CREATE A DICTIONARY OBJECT FOR ATTRIBUTES (setq $objDict (entmakex $objList)) ; ADD THE ATTRIBUTES DICTIONARY TO THE EXTENSION DICTIONARY (setq $objFeatureAttributes (dictadd $extensionDict $featureAttributes $objDict ) ) ) ;_ progn ; ELSE GET THE EXISTING ATTRIBUTES DICTIONARY (setq $objFeatureAttributes (handent (cdr (assoc 5 (dictsearch $extensionDict $featureAttributes ) ) ) ) ) ) ;_ FIND/ADD THE ATTRIBUTES DICTIONARY ; SET ATTRIBUTE FIELD NAMES (setq $fieldnameLong "DIAMETER") ; SET ATTRIBUTE VALUES (setq $fieldDefaultLong 600) ; CREATE/ADD A FIELD DEFINITION FOR LONG INTEGER (if (= (dictsearch $objFeatureAttributes $fieldnameLong) nil) (progn ; CONSTRUCT THE DATA LIST (setq $objResB (cons 90 $fieldDefaultLong)) ; change to 1, 40, 70, 90 depending on data type ; CREATE THE XRECORD LIST (setq $objList (append (list '(0 . "Xrecord") '(100 . "AcDbXrecord")) (list $objResB) ) ) ; MAKE THE XRECORD OBJECT (setq $objXrecd (entmakex $objList)) ; ADD THE XRECORD OBJECT TO THE ATTRIBUTES DICTIONARY (setq $objFieldInt (dictadd $objFeatureAttributes $fieldnameLong $objXrecd ) ) ; INFORM USER (prompt (strcat "\n Fieldname = " $fieldnameLong "\n Data type = Long Integer" ; change this too "\n Default value = " (itoa $fieldDefaultLong) ) ) ) ;_ progn (prompt (strcat "\n Fieldname " $fieldnameLong " already exists")) ) ;_ if CREATE/ADD A FIELD DEFINITION FOR LONG INTEGER ; ELSE INFORM USER EXTENSION DICTIONARY NOT FOUND (progn (princ "No extension dictionary found\n") (princ) ) ) ;_ if CHECK IF EXTENSION DICTIONARY EXISTS ) ;_ defun main function Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.